FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gh-aw/docs/scripts/generate-autocomplete-data.js at main · github/gh-aw · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
gh-aw
Public
Notifications
You must be signed in to change notification settings
Fork
540
Star
5.1k
Code
Issues
399
Pull requests
4
Discussions
Actions
Projects
Wiki
Security and quality
10
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
gh-aw
/
docs
/
scripts
/
generate-autocomplete-data.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
246 lines (217 loc) · 6.23 KB
Breadcrumbs
gh-aw
/
docs
/
scripts
/
generate-autocomplete-data.js
Copy path
File metadata and controls
246 lines (217 loc) · 6.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/env node
/**
* Generates a compact autocomplete data file from the main workflow JSON Schema.
*
* Usage:
* node docs/scripts/generate-autocomplete-data.js
*
* Input: pkg/parser/schemas/main_workflow_schema.json
* Output: docs/public/editor/autocomplete-data.json
*/
import
fs
from
"fs"
;
import
path
from
"path"
;
import
{
fileURLToPath
}
from
"url"
;
const
__filename
=
fileURLToPath
(
import
.
meta
.
url
)
;
const
__dirname
=
path
.
dirname
(
__filename
)
;
const
SCHEMA_PATH
=
path
.
resolve
(
__dirname
,
"../../pkg/parser/schemas/main_workflow_schema.json"
)
;
const
OUTPUT_PATH
=
path
.
resolve
(
__dirname
,
"../public/editor/autocomplete-data.json"
)
;
const
MAX_DEPTH
=
3
;
// Sections where we limit child recursion to just 1 level (key + desc/type only)
const
SHALLOW_SECTIONS
=
new
Set
(
[
"safe-outputs"
,
"on"
]
)
;
const
schema
=
JSON
.
parse
(
fs
.
readFileSync
(
SCHEMA_PATH
,
"utf-8"
)
)
;
const
defs
=
schema
.
$defs
||
{
}
;
// Priority ordering for root-level keys in suggestions
const
ROOT_SORT_ORDER
=
[
"name"
,
"description"
,
"intent"
,
"on"
,
"engine"
,
"permissions"
,
"tools"
,
"safe-outputs"
,
"mcp-servers"
,
"env"
,
"imports"
,
"command"
,
"cache"
,
"labels"
,
"metadata"
,
"tracker-id"
,
"source"
,
"run-name"
,
"runs-on"
,
"timeout-minutes"
,
"concurrency"
,
"environment"
,
"container"
,
"services"
,
"network"
,
"sandbox"
,
"plugins"
,
"if"
,
"steps"
,
"post-steps"
,
"features"
,
"secrets"
,
"secret-masking"
,
"bots"
,
"user-rate-limit"
,
"strict"
,
"safe-inputs"
,
"runtimes"
,
"jobs"
,
]
;
/**
* Resolve $ref pointers to their definitions.
*/
function
resolveRef
(
node
)
{
if
(
!
node
||
typeof
node
!==
"object"
)
return
node
;
if
(
node
.
$ref
)
{
const
refPath
=
node
.
$ref
.
replace
(
"#/$defs/"
,
""
)
;
const
resolved
=
defs
[
refPath
]
;
if
(
!
resolved
)
return
node
;
return
node
.
description
?
{
...
resolved
,
description
:
node
.
description
}
:
resolved
;
}
return
node
;
}
/**
* Extract a compact type string from a schema node.
*/
function
getType
(
node
)
{
if
(
!
node
)
return
"unknown"
;
if
(
node
.
type
)
{
if
(
Array
.
isArray
(
node
.
type
)
)
return
node
.
type
.
join
(
"|"
)
;
return
node
.
type
;
}
if
(
node
.
oneOf
)
{
const
types
=
node
.
oneOf
.
map
(
o
=>
resolveRef
(
o
)
.
type
)
.
filter
(
Boolean
)
;
const
unique
=
[
...
new
Set
(
types
.
flat
(
)
)
]
;
return
unique
.
join
(
"|"
)
||
"unknown"
;
}
if
(
node
.
enum
)
return
"string"
;
return
"unknown"
;
}
/**
* Collect enum values from a schema node, including through oneOf.
*/
function
getEnum
(
node
)
{
if
(
node
.
enum
)
return
node
.
enum
;
if
(
node
.
oneOf
)
{
for
(
const
variant
of
node
.
oneOf
)
{
const
resolved
=
resolveRef
(
variant
)
;
if
(
resolved
.
enum
)
return
resolved
.
enum
;
}
}
return
null
;
}
/**
* Truncate description to a reasonable length.
*/
function
truncDesc
(
desc
)
{
if
(
!
desc
)
return
undefined
;
const
firstSentence
=
desc
.
split
(
/
\.
\s
/
)
[
0
]
;
if
(
firstSentence
.
length
<=
120
)
return
firstSentence
+
(
desc
.
length
>
firstSentence
.
length
?
"."
:
""
)
;
return
desc
.
substring
(
0
,
117
)
+
"..."
;
}
/**
* Determine if this schema node represents an object with known children.
*/
function
getObjectProperties
(
node
)
{
const
resolved
=
resolveRef
(
node
)
;
if
(
resolved
.
properties
)
return
resolved
.
properties
;
if
(
resolved
.
oneOf
)
{
for
(
const
variant
of
resolved
.
oneOf
)
{
const
r
=
resolveRef
(
variant
)
;
if
(
r
.
type
===
"object"
&&
r
.
properties
)
return
r
.
properties
;
}
}
return
null
;
}
/**
* Check if a schema node can be a simple leaf (string, number, boolean, etc.)
*/
function
canBeLeaf
(
node
)
{
const
resolved
=
resolveRef
(
node
)
;
const
type
=
resolved
.
type
;
if
(
type
===
"string"
||
type
===
"integer"
||
type
===
"number"
||
type
===
"boolean"
)
return
true
;
if
(
Array
.
isArray
(
type
)
&&
type
.
some
(
t
=>
t
===
"string"
||
t
===
"integer"
||
t
===
"number"
||
t
===
"boolean"
)
)
return
true
;
if
(
resolved
.
oneOf
)
{
return
resolved
.
oneOf
.
some
(
v
=>
{
const
r
=
resolveRef
(
v
)
;
return
r
.
type
===
"string"
||
r
.
type
===
"integer"
||
r
.
type
===
"number"
||
r
.
type
===
"boolean"
||
r
.
type
===
"null"
;
}
)
;
}
return
false
;
}
/**
* Check if a node can be an array.
*/
function
canBeArray
(
node
)
{
const
resolved
=
resolveRef
(
node
)
;
if
(
resolved
.
type
===
"array"
)
return
true
;
if
(
resolved
.
oneOf
)
{
return
resolved
.
oneOf
.
some
(
v
=>
resolveRef
(
v
)
.
type
===
"array"
)
;
}
return
false
;
}
/**
* Build a compact autocomplete entry from a schema property.
*/
function
buildEntry
(
propSchema
,
depth
)
{
const
resolved
=
resolveRef
(
propSchema
)
;
const
entry
=
{
}
;
const
type
=
getType
(
resolved
)
;
if
(
type
!==
"unknown"
)
entry
.
type
=
type
;
const
desc
=
truncDesc
(
resolved
.
description
)
;
if
(
desc
)
entry
.
desc
=
desc
;
const
enumVals
=
getEnum
(
resolved
)
;
if
(
enumVals
)
{
const
filtered
=
enumVals
.
filter
(
v
=>
v
!=
null
)
;
if
(
filtered
.
length
>
0
)
entry
.
enum
=
filtered
;
}
if
(
type
===
"boolean"
&&
!
entry
.
enum
)
{
entry
.
enum
=
[
true
,
false
]
;
}
if
(
resolved
.
deprecated
===
true
)
{
entry
.
deprecated
=
true
;
}
if
(
typeof
resolved
[
"x-deprecation-message"
]
===
"string"
&&
resolved
[
"x-deprecation-message"
]
)
{
entry
[
"x-deprecation-message"
]
=
resolved
[
"x-deprecation-message"
]
;
}
if
(
depth
<
MAX_DEPTH
)
{
const
childProps
=
getObjectProperties
(
resolved
)
;
if
(
childProps
)
{
const
children
=
{
}
;
for
(
const
[
key
,
childSchema
]
of
Object
.
entries
(
childProps
)
)
{
children
[
key
]
=
buildEntry
(
childSchema
,
depth
+
1
)
;
}
if
(
Object
.
keys
(
children
)
.
length
>
0
)
{
entry
.
children
=
children
;
}
}
}
if
(
!
entry
.
children
&&
canBeLeaf
(
resolved
)
)
{
entry
.
leaf
=
true
;
}
if
(
canBeArray
(
resolved
)
)
{
entry
.
array
=
true
;
}
return
entry
;
}
// Build root-level entries
const
root
=
{
}
;
for
(
const
[
key
,
propSchema
]
of
Object
.
entries
(
schema
.
properties
)
)
{
// For shallow sections, limit recursion depth so children don't bloat the output
const
effectiveDepth
=
SHALLOW_SECTIONS
.
has
(
key
)
?
MAX_DEPTH
-
1
:
0
;
root
[
key
]
=
buildEntry
(
propSchema
,
effectiveDepth
)
;
}
const
output
=
{
root
,
sortOrder
:
ROOT_SORT_ORDER
,
}
;
fs
.
writeFileSync
(
OUTPUT_PATH
,
JSON
.
stringify
(
output
,
null
,
2
)
)
;
const
stats
=
fs
.
statSync
(
OUTPUT_PATH
)
;
console
.
log
(
`Generated
${
OUTPUT_PATH
}
`
)
;
console
.
log
(
` Size:
${
(
stats
.
size
/
1024
)
.
toFixed
(
1
)
}
KB`
)
;
console
.
log
(
` Root keys:
${
Object
.
keys
(
root
)
.
length
}
`
)
;
Back
|
FazBrowse Home
|
New Git URL