@avocadostudio-ai/orchestrator-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/dist/agent/agent-context.d.ts +19 -0
- package/dist/agent/agent-context.js +67 -0
- package/dist/agent/agent-logger.d.ts +5 -0
- package/dist/agent/agent-logger.js +22 -0
- package/dist/agent/agent-loop-openai.d.ts +8 -0
- package/dist/agent/agent-loop-openai.js +172 -0
- package/dist/agent/agent-loop.d.ts +56 -0
- package/dist/agent/agent-loop.js +167 -0
- package/dist/agent/agent-provider.d.ts +28 -0
- package/dist/agent/agent-provider.js +63 -0
- package/dist/agent/agent-tools.d.ts +28 -0
- package/dist/agent/agent-tools.js +899 -0
- package/dist/agent/context/editing-guidelines.md +46 -0
- package/dist/agent/context/role.md +39 -0
- package/dist/agent/integration-prompt.d.ts +9 -0
- package/dist/agent/integration-prompt.js +154 -0
- package/dist/agent/sites-agent-context.d.ts +12 -0
- package/dist/agent/sites-agent-context.js +316 -0
- package/dist/agent/sites-agent-shared.d.ts +161 -0
- package/dist/agent/sites-agent-shared.js +1101 -0
- package/dist/agent/sites-agent-tools.d.ts +18 -0
- package/dist/agent/sites-agent-tools.js +1227 -0
- package/dist/chat/anthropic-cache.d.ts +20 -0
- package/dist/chat/anthropic-cache.js +54 -0
- package/dist/chat/anthropic-planner.d.ts +98 -0
- package/dist/chat/anthropic-planner.js +1012 -0
- package/dist/chat/changelog-coverage-validator.d.ts +37 -0
- package/dist/chat/changelog-coverage-validator.js +215 -0
- package/dist/chat/chat-pipeline-context.d.ts +211 -0
- package/dist/chat/chat-pipeline-context.js +249 -0
- package/dist/chat/chat-pipeline-deterministic.d.ts +61 -0
- package/dist/chat/chat-pipeline-deterministic.js +407 -0
- package/dist/chat/chat-pipeline-image.d.ts +86 -0
- package/dist/chat/chat-pipeline-image.js +897 -0
- package/dist/chat/chat-pipeline-shared.d.ts +69 -0
- package/dist/chat/chat-pipeline-shared.js +212 -0
- package/dist/chat/chat-pipeline-translation.d.ts +27 -0
- package/dist/chat/chat-pipeline-translation.js +417 -0
- package/dist/chat/chat-pipeline-ui.d.ts +14 -0
- package/dist/chat/chat-pipeline-ui.js +244 -0
- package/dist/chat/chat-pipeline.d.ts +99 -0
- package/dist/chat/chat-pipeline.js +3999 -0
- package/dist/chat/decomposer.d.ts +21 -0
- package/dist/chat/decomposer.js +65 -0
- package/dist/chat/gemini-planner.d.ts +70 -0
- package/dist/chat/gemini-planner.js +541 -0
- package/dist/chat/hallucination-validator.d.ts +36 -0
- package/dist/chat/hallucination-validator.js +110 -0
- package/dist/chat/locale-strings.d.ts +47 -0
- package/dist/chat/locale-strings.js +100 -0
- package/dist/chat/plan-json-schema.d.ts +133 -0
- package/dist/chat/plan-json-schema.js +112 -0
- package/dist/chat/planner-types.d.ts +120 -0
- package/dist/chat/planner-types.js +66 -0
- package/dist/chat/planner.d.ts +148 -0
- package/dist/chat/planner.js +1361 -0
- package/dist/chat/prompts.d.ts +67 -0
- package/dist/chat/prompts.js +356 -0
- package/dist/chat/provider-routing.d.ts +14 -0
- package/dist/chat/provider-routing.js +27 -0
- package/dist/chat/variation-pipeline.d.ts +135 -0
- package/dist/chat/variation-pipeline.js +837 -0
- package/dist/chat/vision-alt-generator.d.ts +35 -0
- package/dist/chat/vision-alt-generator.js +152 -0
- package/dist/cms/adapter.d.ts +62 -0
- package/dist/cms/adapter.js +1 -0
- package/dist/cms/bootstrap.d.ts +17 -0
- package/dist/cms/bootstrap.js +85 -0
- package/dist/cms/editor-api-adapter.d.ts +23 -0
- package/dist/cms/editor-api-adapter.js +71 -0
- package/dist/cms/index.d.ts +4 -0
- package/dist/cms/index.js +3 -0
- package/dist/cms/json-file-adapter.d.ts +11 -0
- package/dist/cms/json-file-adapter.js +62 -0
- package/dist/demo-mode.d.ts +59 -0
- package/dist/demo-mode.js +201 -0
- package/dist/errors.d.ts +67 -0
- package/dist/errors.js +129 -0
- package/dist/http/chat-stream-resumable.d.ts +108 -0
- package/dist/http/chat-stream-resumable.js +290 -0
- package/dist/http/chat-stream.d.ts +99 -0
- package/dist/http/chat-stream.js +92 -0
- package/dist/image/gdrive-client.d.ts +22 -0
- package/dist/image/gdrive-client.js +215 -0
- package/dist/image/image-helpers.d.ts +95 -0
- package/dist/image/image-helpers.js +488 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/jira/jira-approval.d.ts +22 -0
- package/dist/jira/jira-approval.js +51 -0
- package/dist/jira/jira-client.d.ts +44 -0
- package/dist/jira/jira-client.js +313 -0
- package/dist/jira/jira-poller.d.ts +46 -0
- package/dist/jira/jira-poller.js +184 -0
- package/dist/jira/jira-processor.d.ts +103 -0
- package/dist/jira/jira-processor.js +1085 -0
- package/dist/jira/jira-types.d.ts +117 -0
- package/dist/jira/jira-types.js +38 -0
- package/dist/logger.d.ts +12 -0
- package/dist/logger.js +28 -0
- package/dist/migration/mcp-server-stdio.d.ts +8 -0
- package/dist/migration/mcp-server-stdio.js +672 -0
- package/dist/migration/migration-prompt.d.ts +7 -0
- package/dist/migration/migration-prompt.js +197 -0
- package/dist/migration/migration-tools.d.ts +17 -0
- package/dist/migration/migration-tools.js +159 -0
- package/dist/migration/scrape-cache.d.ts +9 -0
- package/dist/migration/scrape-cache.js +19 -0
- package/dist/nlp/deterministic-planner-context.d.ts +141 -0
- package/dist/nlp/deterministic-planner-context.js +362 -0
- package/dist/nlp/deterministic-planner-pages.d.ts +26 -0
- package/dist/nlp/deterministic-planner-pages.js +170 -0
- package/dist/nlp/deterministic-planner-patches.d.ts +80 -0
- package/dist/nlp/deterministic-planner-patches.js +508 -0
- package/dist/nlp/deterministic-planner-refs.d.ts +33 -0
- package/dist/nlp/deterministic-planner-refs.js +164 -0
- package/dist/nlp/deterministic-planner-suggestions.d.ts +49 -0
- package/dist/nlp/deterministic-planner-suggestions.js +579 -0
- package/dist/nlp/deterministic-planner.d.ts +85 -0
- package/dist/nlp/deterministic-planner.js +1631 -0
- package/dist/nlp/intent-detection.d.ts +309 -0
- package/dist/nlp/intent-detection.js +730 -0
- package/dist/nlp/intent-helpers.d.ts +15 -0
- package/dist/nlp/intent-helpers.js +243 -0
- package/dist/nlp/intent-patterns.d.ts +40 -0
- package/dist/nlp/intent-patterns.js +223 -0
- package/dist/nlp/plan-normalizer.d.ts +41 -0
- package/dist/nlp/plan-normalizer.js +1537 -0
- package/dist/ops/destructive-action-gate.d.ts +44 -0
- package/dist/ops/destructive-action-gate.js +90 -0
- package/dist/ops/ops-engine.d.ts +151 -0
- package/dist/ops/ops-engine.js +1394 -0
- package/dist/publish/diff-engine.d.ts +18 -0
- package/dist/publish/diff-engine.js +305 -0
- package/dist/publish/publish-helpers.d.ts +87 -0
- package/dist/publish/publish-helpers.js +521 -0
- package/dist/publish/publish-target-registry.d.ts +7 -0
- package/dist/publish/publish-target-registry.js +61 -0
- package/dist/publish/publish-target.d.ts +81 -0
- package/dist/publish/publish-target.js +1 -0
- package/dist/publish/targets/deploy-hook.d.ts +13 -0
- package/dist/publish/targets/deploy-hook.js +123 -0
- package/dist/publish/targets/git.d.ts +13 -0
- package/dist/publish/targets/git.js +55 -0
- package/dist/publish/targets/site-contract.d.ts +19 -0
- package/dist/publish/targets/site-contract.js +124 -0
- package/dist/state/content-source.d.ts +17 -0
- package/dist/state/content-source.js +1 -0
- package/dist/state/in-memory-content-source.d.ts +27 -0
- package/dist/state/in-memory-content-source.js +51 -0
- package/dist/state/session-lock.d.ts +13 -0
- package/dist/state/session-lock.js +29 -0
- package/dist/state/session-state.d.ts +310 -0
- package/dist/state/session-state.js +1083 -0
- package/dist/state/sqlite-store-singleton.d.ts +31 -0
- package/dist/state/sqlite-store-singleton.js +170 -0
- package/dist/state/sqlite-store.d.ts +135 -0
- package/dist/state/sqlite-store.js +421 -0
- package/dist/telemetry/chat-telemetry.d.ts +105 -0
- package/dist/telemetry/chat-telemetry.js +247 -0
- package/dist/telemetry/eval-candidate-store.d.ts +50 -0
- package/dist/telemetry/eval-candidate-store.js +120 -0
- package/dist/telemetry/feedback-store.d.ts +34 -0
- package/dist/telemetry/feedback-store.js +76 -0
- package/dist/telemetry/jira-telemetry.d.ts +57 -0
- package/dist/telemetry/jira-telemetry.js +68 -0
- package/dist/telemetry/migration-telemetry.d.ts +35 -0
- package/dist/telemetry/migration-telemetry.js +40 -0
- package/dist/telemetry/usage.d.ts +24 -0
- package/dist/telemetry/usage.js +80 -0
- package/dist/tools/builtin-registrations.d.ts +12 -0
- package/dist/tools/builtin-registrations.js +33 -0
- package/dist/tools/builtins/gdrive-browse.d.ts +3 -0
- package/dist/tools/builtins/gdrive-browse.js +68 -0
- package/dist/tools/builtins/image-generate.d.ts +3 -0
- package/dist/tools/builtins/image-generate.js +211 -0
- package/dist/tools/builtins/unsplash-get-by-id.d.ts +23 -0
- package/dist/tools/builtins/unsplash-get-by-id.js +119 -0
- package/dist/tools/builtins/unsplash-search.d.ts +3 -0
- package/dist/tools/builtins/unsplash-search.js +74 -0
- package/dist/tools/executor.d.ts +23 -0
- package/dist/tools/executor.js +169 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.js +5 -0
- package/dist/tools/registry.d.ts +21 -0
- package/dist/tools/registry.js +75 -0
- package/dist/tools/runtime.d.ts +27 -0
- package/dist/tools/runtime.js +48 -0
- package/dist/tools/schema-validator.d.ts +24 -0
- package/dist/tools/schema-validator.js +88 -0
- package/dist/tools/types.d.ts +86 -0
- package/dist/tools/types.js +1 -0
- package/dist/variation-images.d.ts +19 -0
- package/dist/variation-images.js +12 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Avocado Studio Contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the system prompt for the agent from .md context files and runtime state.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Build the full system prompt for an agent session.
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildAgentSystemPrompt(options?: {
|
|
8
|
+
locale?: string;
|
|
9
|
+
sitePurpose?: string;
|
|
10
|
+
}): string;
|
|
11
|
+
/**
|
|
12
|
+
* Build a context message describing the current page state.
|
|
13
|
+
* This goes in the user message, not the system prompt.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildContextMessage(session: string, options: {
|
|
16
|
+
slug: string;
|
|
17
|
+
activeBlockId?: string;
|
|
18
|
+
activeEditablePath?: string;
|
|
19
|
+
}): string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the system prompt for the agent from .md context files and runtime state.
|
|
3
|
+
*/
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { resolve, dirname } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { getPage, getSessionDraft, orderSlugsHomeFirst } from "../state/session-state.js";
|
|
8
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
function readContextFile(name) {
|
|
10
|
+
try {
|
|
11
|
+
return readFileSync(resolve(__dirname, "context", name), "utf-8").trim();
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const roleContext = readContextFile("role.md");
|
|
18
|
+
const editingGuidelines = readContextFile("editing-guidelines.md");
|
|
19
|
+
/**
|
|
20
|
+
* Build the full system prompt for an agent session.
|
|
21
|
+
*/
|
|
22
|
+
export function buildAgentSystemPrompt(options) {
|
|
23
|
+
const parts = [roleContext, editingGuidelines];
|
|
24
|
+
if (options?.sitePurpose) {
|
|
25
|
+
parts.push(`## Site Purpose\nThis website is: ${options.sitePurpose}`);
|
|
26
|
+
}
|
|
27
|
+
if (options?.locale && options.locale !== "en") {
|
|
28
|
+
parts.push(`## Language\nRespond to the user in ${options.locale}. Tool inputs (block props, field names) stay in English. Only user-facing summaries and explanations should be in ${options.locale}.`);
|
|
29
|
+
}
|
|
30
|
+
return parts.filter(Boolean).join("\n\n---\n\n");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build a context message describing the current page state.
|
|
34
|
+
* This goes in the user message, not the system prompt.
|
|
35
|
+
*/
|
|
36
|
+
export function buildContextMessage(session, options) {
|
|
37
|
+
const page = getPage(session, options.slug);
|
|
38
|
+
if (!page)
|
|
39
|
+
return `[Page "${options.slug}" not found in session]`;
|
|
40
|
+
const draft = getSessionDraft(session);
|
|
41
|
+
const slugs = orderSlugsHomeFirst(Array.from(draft.keys()));
|
|
42
|
+
const parts = [];
|
|
43
|
+
// Site overview
|
|
44
|
+
parts.push(`Site has ${slugs.length} page(s): ${slugs.join(", ")}`);
|
|
45
|
+
// Current page
|
|
46
|
+
parts.push(`Current page: "${page.title}" (${options.slug})`);
|
|
47
|
+
parts.push(`Blocks (${page.blocks.length}):`);
|
|
48
|
+
for (const block of page.blocks) {
|
|
49
|
+
const propsPreview = Object.entries(block.props)
|
|
50
|
+
.filter(([, v]) => typeof v === "string" && v.length > 0 && v.length < 100)
|
|
51
|
+
.map(([k, v]) => `${k}: "${v}"`)
|
|
52
|
+
.join(", ");
|
|
53
|
+
parts.push(` - ${block.type} (${block.id})${propsPreview ? `: ${propsPreview}` : ""}`);
|
|
54
|
+
}
|
|
55
|
+
// Selected block context
|
|
56
|
+
if (options.activeBlockId) {
|
|
57
|
+
const block = page.blocks.find((b) => b.id === options.activeBlockId);
|
|
58
|
+
if (block) {
|
|
59
|
+
parts.push(`\nSelected block: ${block.type} (${block.id})`);
|
|
60
|
+
parts.push(`Full props: ${JSON.stringify(block.props, null, 2)}`);
|
|
61
|
+
if (options.activeEditablePath) {
|
|
62
|
+
parts.push(`Selected field: ${options.activeEditablePath}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return parts.join("\n");
|
|
67
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistent agent logger — appends NDJSON to .data/agent-log.ndjson.
|
|
3
|
+
* Complements console.log (stdout) so agent timing data survives restarts.
|
|
4
|
+
*/
|
|
5
|
+
export declare function logAgent(streamId: string, event: string, detail?: Record<string, unknown>, startedAt?: number): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistent agent logger — appends NDJSON to .data/agent-log.ndjson.
|
|
3
|
+
* Complements console.log (stdout) so agent timing data survives restarts.
|
|
4
|
+
*/
|
|
5
|
+
import { appendFileSync } from "node:fs";
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
const LOG_PATH = resolve(process.cwd(), "../../.data/agent-log.ndjson");
|
|
8
|
+
export function logAgent(streamId, event, detail, startedAt) {
|
|
9
|
+
const entry = {
|
|
10
|
+
ts: Date.now(),
|
|
11
|
+
elapsed: startedAt ? +((Date.now() - startedAt) / 1000).toFixed(1) : undefined,
|
|
12
|
+
stream: streamId.slice(0, 8),
|
|
13
|
+
event,
|
|
14
|
+
...detail,
|
|
15
|
+
};
|
|
16
|
+
try {
|
|
17
|
+
appendFileSync(LOG_PATH, JSON.stringify(entry) + "\n");
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// silently ignore — logging should never break the agent
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI agent loop: multi-turn tool-use conversation via Chat Completions API with streaming.
|
|
3
|
+
*
|
|
4
|
+
* Yields the same AgentEvent types as the Anthropic loop so the SSE transport
|
|
5
|
+
* and editor UI work identically regardless of provider.
|
|
6
|
+
*/
|
|
7
|
+
import { type AgentEvent, type AgentLoopOptions } from "./agent-loop.ts";
|
|
8
|
+
export declare function runOpenAIAgentLoop(options: AgentLoopOptions): AsyncGenerator<AgentEvent>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI agent loop: multi-turn tool-use conversation via Chat Completions API with streaming.
|
|
3
|
+
*
|
|
4
|
+
* Yields the same AgentEvent types as the Anthropic loop so the SSE transport
|
|
5
|
+
* and editor UI work identically regardless of provider.
|
|
6
|
+
*/
|
|
7
|
+
import OpenAI from "openai";
|
|
8
|
+
import { openAIChatOptionsForModel } from "../chat/planner.js";
|
|
9
|
+
import { AGENT_MAX_TOOL_CALLS, AGENT_MAX_TOKENS } from "./agent-provider.js";
|
|
10
|
+
import { consoleAgentLogger } from "./agent-loop.js";
|
|
11
|
+
function agentToolToOpenAI(tool) {
|
|
12
|
+
return {
|
|
13
|
+
type: "function",
|
|
14
|
+
function: {
|
|
15
|
+
name: tool.definition.name,
|
|
16
|
+
description: tool.definition.description ?? "",
|
|
17
|
+
parameters: tool.definition.input_schema,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export async function* runOpenAIAgentLoop(options) {
|
|
22
|
+
const { apiKey, model, systemPrompt, tools, userMessage, maxToolCalls = AGENT_MAX_TOOL_CALLS, signal, logger, } = options;
|
|
23
|
+
const log = logger ?? consoleAgentLogger;
|
|
24
|
+
const client = new OpenAI({ apiKey });
|
|
25
|
+
const openAITools = tools.map(agentToolToOpenAI);
|
|
26
|
+
const handlerMap = new Map(tools.map((t) => [t.definition.name, t.handler]));
|
|
27
|
+
const messages = [
|
|
28
|
+
{ role: "system", content: systemPrompt },
|
|
29
|
+
{ role: "user", content: userMessage },
|
|
30
|
+
];
|
|
31
|
+
let toolCallCount = 0;
|
|
32
|
+
let fullSummary = "";
|
|
33
|
+
const totalUsage = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheCreationTokens: 0 };
|
|
34
|
+
const modelOptions = openAIChatOptionsForModel(model);
|
|
35
|
+
while (toolCallCount < maxToolCalls) {
|
|
36
|
+
if (signal?.aborted) {
|
|
37
|
+
yield { type: "error", message: "Canceled" };
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const textParts = [];
|
|
41
|
+
const toolCallAccumulators = new Map();
|
|
42
|
+
let finishReason = null;
|
|
43
|
+
try {
|
|
44
|
+
log.info(`[agent-loop-openai] Calling OpenAI API (streaming), turn ${toolCallCount + 1}`);
|
|
45
|
+
const stream = await client.chat.completions.create({
|
|
46
|
+
model,
|
|
47
|
+
max_tokens: AGENT_MAX_TOKENS,
|
|
48
|
+
messages,
|
|
49
|
+
tools: openAITools,
|
|
50
|
+
stream: true,
|
|
51
|
+
...modelOptions,
|
|
52
|
+
}, { signal });
|
|
53
|
+
for await (const chunk of stream) {
|
|
54
|
+
// Accumulate usage from streaming chunks
|
|
55
|
+
if (chunk.usage) {
|
|
56
|
+
totalUsage.inputTokens += chunk.usage.prompt_tokens ?? 0;
|
|
57
|
+
totalUsage.outputTokens += chunk.usage.completion_tokens ?? 0;
|
|
58
|
+
}
|
|
59
|
+
if (signal?.aborted) {
|
|
60
|
+
yield { type: "error", message: "Canceled" };
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const choice = chunk.choices[0];
|
|
64
|
+
if (!choice)
|
|
65
|
+
continue;
|
|
66
|
+
const delta = choice.delta;
|
|
67
|
+
// Text content
|
|
68
|
+
if (delta?.content) {
|
|
69
|
+
textParts.push(delta.content);
|
|
70
|
+
yield { type: "text_delta", text: delta.content };
|
|
71
|
+
}
|
|
72
|
+
// Tool call deltas — accumulate per index
|
|
73
|
+
if (delta?.tool_calls) {
|
|
74
|
+
for (const tc of delta.tool_calls) {
|
|
75
|
+
let acc = toolCallAccumulators.get(tc.index);
|
|
76
|
+
if (!acc) {
|
|
77
|
+
acc = { id: tc.id ?? "", name: tc.function?.name ?? "", args: "" };
|
|
78
|
+
toolCallAccumulators.set(tc.index, acc);
|
|
79
|
+
}
|
|
80
|
+
if (tc.id)
|
|
81
|
+
acc.id = tc.id;
|
|
82
|
+
if (tc.function?.name)
|
|
83
|
+
acc.name = tc.function.name;
|
|
84
|
+
if (tc.function?.arguments)
|
|
85
|
+
acc.args += tc.function.arguments;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (choice.finish_reason) {
|
|
89
|
+
finishReason = choice.finish_reason;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
if (signal?.aborted) {
|
|
95
|
+
yield { type: "error", message: "Canceled" };
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
99
|
+
log.error(`[agent-loop-openai] API error: ${msg}`);
|
|
100
|
+
yield { type: "error", message: msg };
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const turnText = textParts.join("");
|
|
104
|
+
// Build assistant message for conversation history
|
|
105
|
+
const assistantMessage = {
|
|
106
|
+
role: "assistant",
|
|
107
|
+
content: turnText || null,
|
|
108
|
+
...(toolCallAccumulators.size > 0
|
|
109
|
+
? {
|
|
110
|
+
tool_calls: [...toolCallAccumulators.values()].map((acc) => ({
|
|
111
|
+
id: acc.id,
|
|
112
|
+
type: "function",
|
|
113
|
+
function: { name: acc.name, arguments: acc.args },
|
|
114
|
+
})),
|
|
115
|
+
}
|
|
116
|
+
: {}),
|
|
117
|
+
};
|
|
118
|
+
messages.push(assistantMessage);
|
|
119
|
+
// Handle non-tool finish reasons
|
|
120
|
+
if (finishReason === "length") {
|
|
121
|
+
yield { type: "error", message: "Response truncated — max tokens reached" };
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (finishReason === "content_filter") {
|
|
125
|
+
yield { type: "error", message: "Content filtered by OpenAI" };
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
// No tool calls → done
|
|
129
|
+
if (toolCallAccumulators.size === 0 || finishReason === "stop") {
|
|
130
|
+
fullSummary += turnText;
|
|
131
|
+
yield { type: "done", summary: fullSummary, toolCallCount, usage: totalUsage };
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
// Execute tool calls
|
|
135
|
+
const toolResults = [];
|
|
136
|
+
for (const [, acc] of toolCallAccumulators) {
|
|
137
|
+
if (signal?.aborted) {
|
|
138
|
+
yield { type: "error", message: "Canceled" };
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
toolCallCount++;
|
|
142
|
+
yield { type: "tool_start", toolName: acc.name, toolUseId: acc.id };
|
|
143
|
+
let input;
|
|
144
|
+
try {
|
|
145
|
+
input = JSON.parse(acc.args || "{}");
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
const errorResult = `Failed to parse tool arguments for ${acc.name}`;
|
|
149
|
+
log.error(`[agent-loop-openai] ${errorResult} raw: ${acc.args.slice(0, 200)}`);
|
|
150
|
+
toolResults.push({ role: "tool", tool_call_id: acc.id, content: errorResult });
|
|
151
|
+
yield { type: "tool_done", toolName: acc.name, toolUseId: acc.id, result: errorResult, isError: true };
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
log.info(`[agent-loop-openai] Executing tool: ${acc.name} input: ${JSON.stringify(input).slice(0, 200)}`);
|
|
155
|
+
const handler = handlerMap.get(acc.name);
|
|
156
|
+
if (!handler) {
|
|
157
|
+
const errorResult = `Unknown tool: ${acc.name}`;
|
|
158
|
+
toolResults.push({ role: "tool", tool_call_id: acc.id, content: errorResult });
|
|
159
|
+
yield { type: "tool_done", toolName: acc.name, toolUseId: acc.id, result: errorResult, isError: true };
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const { result, isError } = await handler(input);
|
|
163
|
+
toolResults.push({ role: "tool", tool_call_id: acc.id, content: result });
|
|
164
|
+
yield { type: "tool_done", toolName: acc.name, toolUseId: acc.id, result, isError };
|
|
165
|
+
}
|
|
166
|
+
if (turnText) {
|
|
167
|
+
fullSummary += turnText;
|
|
168
|
+
}
|
|
169
|
+
messages.push(...toolResults);
|
|
170
|
+
}
|
|
171
|
+
yield { type: "done", summary: `Completed with ${toolCallCount} tool calls (limit reached).`, toolCallCount, usage: totalUsage };
|
|
172
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent loop: multi-turn tool-use conversation with an LLM.
|
|
3
|
+
*
|
|
4
|
+
* Dispatches to provider-specific implementations (Anthropic / OpenAI) based on
|
|
5
|
+
* the `provider` field in options (required — routes validate before calling).
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentTool } from "./agent-tools.ts";
|
|
8
|
+
import type { AgentProvider } from "./agent-provider.ts";
|
|
9
|
+
export type AgentLogger = {
|
|
10
|
+
info(obj: object | string, msg?: string): void;
|
|
11
|
+
warn(obj: object | string, msg?: string): void;
|
|
12
|
+
error(obj: object | string, msg?: string): void;
|
|
13
|
+
};
|
|
14
|
+
export declare const consoleAgentLogger: AgentLogger;
|
|
15
|
+
export type AgentTokenUsage = {
|
|
16
|
+
inputTokens: number;
|
|
17
|
+
outputTokens: number;
|
|
18
|
+
cacheReadTokens: number;
|
|
19
|
+
cacheCreationTokens: number;
|
|
20
|
+
};
|
|
21
|
+
export type AgentEvent = {
|
|
22
|
+
type: "text_delta";
|
|
23
|
+
text: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: "tool_start";
|
|
26
|
+
toolName: string;
|
|
27
|
+
toolUseId: string;
|
|
28
|
+
} | {
|
|
29
|
+
type: "tool_done";
|
|
30
|
+
toolName: string;
|
|
31
|
+
toolUseId: string;
|
|
32
|
+
result: string;
|
|
33
|
+
isError?: boolean;
|
|
34
|
+
} | {
|
|
35
|
+
type: "done";
|
|
36
|
+
summary: string;
|
|
37
|
+
toolCallCount: number;
|
|
38
|
+
usage: AgentTokenUsage;
|
|
39
|
+
} | {
|
|
40
|
+
type: "error";
|
|
41
|
+
message: string;
|
|
42
|
+
};
|
|
43
|
+
export type AgentLoopOptions = {
|
|
44
|
+
apiKey: string;
|
|
45
|
+
model: string;
|
|
46
|
+
provider: AgentProvider;
|
|
47
|
+
systemPrompt: string;
|
|
48
|
+
tools: AgentTool[];
|
|
49
|
+
userMessage: string;
|
|
50
|
+
maxToolCalls?: number;
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
logger?: AgentLogger;
|
|
53
|
+
};
|
|
54
|
+
/** Provider-agnostic entry point — dispatches to Anthropic or OpenAI loop. */
|
|
55
|
+
export declare function runAgentLoop(options: AgentLoopOptions): AsyncGenerator<AgentEvent>;
|
|
56
|
+
export declare function setRunAgentLoopForTests(fn?: (options: AgentLoopOptions) => AsyncGenerator<AgentEvent>): void;
|