@beeuni/sdk 0.1.0 → 0.3.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/README.md +53 -92
- package/dist/beeuni.esm.min.js +36 -34
- package/dist/beeuni.global.js +36 -34
- package/dist/browser/cache/idb-sync-cache.js +15 -5
- package/dist/browser/session-sync/server-transcript-mirror.d.ts +7 -1
- package/dist/browser/session-sync/server-transcript-mirror.js +30 -24
- package/dist/browser/session-sync/session-sync-registry.d.ts +3 -1
- package/dist/browser/session-sync/session-sync-registry.js +48 -3
- package/dist/browser/stores/sync-store/keep-unchanged.d.ts +4 -0
- package/dist/browser/stores/sync-store/keep-unchanged.js +34 -0
- package/dist/browser/stores/sync-store.d.ts +7 -0
- package/dist/browser/stores/sync-store.js +122 -35
- package/dist/core/attachments/prompt-attachments.d.ts +4 -0
- package/dist/core/attachments/prompt-attachments.js +34 -0
- package/dist/core/capture/rules.d.ts +17 -0
- package/dist/core/capture/rules.js +27 -0
- package/dist/core/client/beeuni.d.ts +99 -34
- package/dist/core/client/beeuni.js +5 -11
- package/dist/core/client/capture.d.ts +105 -0
- package/dist/core/client/capture.js +48 -0
- package/dist/core/client/facade-catalog.d.ts +0 -4
- package/dist/core/client/facade-catalog.js +1 -5
- package/dist/core/client/facade-identity.d.ts +1 -0
- package/dist/core/client/facade-identity.js +1 -0
- package/dist/core/client/project-access-resources.d.ts +3 -1
- package/dist/core/client/project-access-resources.js +1 -1
- package/dist/core/client/project-connections.d.ts +2 -2
- package/dist/core/client/project-connections.js +2 -2
- package/dist/core/client/project-operations-admin.d.ts +4 -4
- package/dist/core/client/project-operations-review.d.ts +2 -3
- package/dist/core/client/project-operations-review.js +1 -0
- package/dist/core/client/project-operations-workspace.d.ts +4 -4
- package/dist/core/client/project-operations-workspace.js +1 -1
- package/dist/core/client/project-operations.d.ts +9 -19
- package/dist/core/client/project-operations.js +2 -6
- package/dist/core/client/project-platform-security.d.ts +1 -1
- package/dist/core/client/project-platform-settings.d.ts +1 -1
- package/dist/core/client/session-context.d.ts +2 -0
- package/dist/core/client/session-handle.d.ts +13 -0
- package/dist/core/client/session-lifecycle-resources.d.ts +11 -0
- package/dist/core/client/session-lifecycle-resources.js +4 -0
- package/dist/core/client/session-lifecycle-security.d.ts +2 -0
- package/dist/core/client/session-lifecycle-security.js +1 -0
- package/dist/core/client/session-readiness.d.ts +2 -0
- package/dist/core/client/session-readiness.js +20 -1
- package/dist/core/http/api-client.d.ts +1 -7
- package/dist/core/http/api-client.js +2 -37
- package/dist/core/http/auth.d.ts +2 -4
- package/dist/core/http/auth.js +2 -8
- package/dist/core/http/config.d.ts +2 -0
- package/dist/core/http/response-error.js +26 -11
- package/dist/core/http/transport.js +6 -1
- package/dist/core/models/composer-model.d.ts +14 -0
- package/dist/core/models/composer-model.js +21 -1
- package/dist/core/rest/platform-client/capture.d.ts +363 -0
- package/dist/core/rest/platform-client/capture.js +116 -0
- package/dist/core/rest/platform-client/client-policy.d.ts +8 -0
- package/dist/core/rest/platform-client/client-policy.js +30 -0
- package/dist/core/rest/platform-client/index.d.ts +4 -4
- package/dist/core/rest/platform-client/index.js +4 -4
- package/dist/core/rest/platform-client/lifecycle.js +18 -12
- package/dist/core/rest/platform-client/shared.d.ts +5 -0
- package/dist/core/rest/platform-client/shared.js +18 -0
- package/dist/core/rest/platform-client/types.d.ts +1 -1
- package/dist/core/rest/projects-client/account-secret-resources.d.ts +2 -1
- package/dist/core/rest/projects-client/accounts.d.ts +34 -0
- package/dist/core/rest/projects-client/accounts.js +10 -0
- package/dist/core/rest/projects-client/admin-providers.d.ts +0 -61
- package/dist/core/rest/projects-client/admin-providers.js +0 -6
- package/dist/core/rest/projects-client/agent-config.d.ts +3 -0
- package/dist/core/rest/projects-client/apps-fleet.d.ts +5 -1
- package/dist/core/rest/projects-client/apps-fleet.js +2 -2
- package/dist/core/rest/projects-client/apps.d.ts +11 -1
- package/dist/core/rest/projects-client/change-requests.d.ts +2 -0
- package/dist/core/rest/projects-client/change-requests.js +2 -0
- package/dist/core/rest/projects-client/connectors.d.ts +13 -55
- package/dist/core/rest/projects-client/connectors.js +5 -29
- package/dist/core/rest/projects-client/files.d.ts +3 -0
- package/dist/core/rest/projects-client/files.js +4 -0
- package/dist/core/rest/projects-client/gateway.d.ts +5 -0
- package/dist/core/rest/projects-client/git-backend.d.ts +1 -10
- package/dist/core/rest/projects-client/git-backend.js +0 -10
- package/dist/core/rest/projects-client/iam-actions.d.ts +76 -0
- package/dist/core/rest/projects-client/iam-actions.js +101 -0
- package/dist/core/rest/projects-client/iam-sso.d.ts +0 -10
- package/dist/core/rest/projects-client/iam-sso.js +0 -3
- package/dist/core/rest/projects-client/iam.d.ts +1 -0
- package/dist/core/rest/projects-client/iam.js +1 -0
- package/dist/core/rest/projects-client/index.d.ts +1 -4
- package/dist/core/rest/projects-client/index.js +1 -4
- package/dist/core/rest/projects-client/notifications.d.ts +1 -1
- package/dist/core/rest/projects-client/notifications.js +4 -0
- package/dist/core/rest/projects-client/projects.d.ts +4 -2
- package/dist/core/rest/projects-client/projects.js +4 -2
- package/dist/core/rest/projects-client/review-items.d.ts +2 -0
- package/dist/core/rest/projects-client/review-items.js +4 -0
- package/dist/core/rest/projects-client/review.d.ts +17 -3
- package/dist/core/rest/projects-client/review.js +11 -0
- package/dist/core/rest/projects-client/sandbox.d.ts +8 -9
- package/dist/core/rest/projects-client/secrets.d.ts +3 -0
- package/dist/core/rest/projects-client/session-attachments.js +14 -1
- package/dist/core/rest/projects-client/session-sandbox.d.ts +1 -1
- package/dist/core/rest/projects-client/sessions.d.ts +31 -4
- package/dist/core/rest/projects-client/sessions.js +34 -4
- package/dist/core/runtime/runtime-rest-client.js +1 -1
- package/dist/core/runtime/runtime-types.d.ts +1 -0
- package/dist/core/session/control-stream.d.ts +1 -0
- package/dist/core/session/control-stream.js +18 -1
- package/dist/core/session/open-bundle.d.ts +4 -4
- package/dist/core/session/open-bundle.js +29 -46
- package/dist/core/session/turn-end-watch.d.ts +47 -0
- package/dist/core/session/turn-end-watch.js +141 -0
- package/dist/core/session-log/guard.d.ts +6 -0
- package/dist/core/session-log/guard.js +109 -0
- package/dist/core/session-log/index.d.ts +7 -0
- package/dist/core/session-log/index.js +5 -0
- package/dist/core/session-log/saved-log.d.ts +10 -0
- package/dist/core/session-log/saved-log.js +25 -0
- package/dist/core/session-log/source.d.ts +25 -0
- package/dist/core/session-log/source.js +30 -0
- package/dist/core/session-log/store.d.ts +21 -0
- package/dist/core/session-log/store.js +126 -0
- package/dist/core/session-log/tool-call.d.ts +11 -0
- package/dist/core/session-log/tool-call.js +65 -0
- package/dist/core/session-log/turns/blocks.d.ts +60 -0
- package/dist/core/session-log/turns/blocks.js +124 -0
- package/dist/core/session-log/turns/history.d.ts +32 -0
- package/dist/core/session-log/turns/history.js +99 -0
- package/dist/core/session-log/turns/index.d.ts +4 -0
- package/dist/core/session-log/turns/index.js +4 -0
- package/dist/core/session-log/turns/metrics.d.ts +21 -0
- package/dist/core/session-log/turns/metrics.js +29 -0
- package/dist/core/session-log/turns/turn.d.ts +55 -0
- package/dist/core/session-log/turns/turn.js +279 -0
- package/dist/core/session-log/turns/v1-parts.d.ts +8 -0
- package/dist/core/session-log/turns/v1-parts.js +43 -0
- package/dist/core/session-log/types.d.ts +264 -0
- package/dist/core/session-log/types.js +6 -0
- package/dist/core/session-log/v1-view.d.ts +13 -0
- package/dist/core/session-log/v1-view.js +215 -0
- package/dist/core/session-log/v1.d.ts +31 -0
- package/dist/core/session-log/v1.js +473 -0
- package/dist/core/session-sync/copy-store-types.d.ts +19 -0
- package/dist/core/session-sync/copy-store-types.js +1 -0
- package/dist/core/session-sync/saved-copy-store.js +25 -4
- package/dist/core/session-sync/saved-transcript.d.ts +15 -1
- package/dist/core/session-sync/saved-transcript.js +55 -0
- package/dist/core/session-sync/session-sync-controller.js +3 -0
- package/dist/core/stream/event-stream.js +2 -2
- package/dist/core/turns/classify.d.ts +2 -1
- package/dist/core/turns/classify.js +7 -3
- package/dist/core/turns/edit-blocks.d.ts +1 -0
- package/dist/core/turns/edit-blocks.js +15 -0
- package/dist/core/turns/parts.d.ts +3 -2
- package/dist/core/turns/parts.js +4 -2
- package/dist/core/turns/segments/burst-summary.d.ts +1 -0
- package/dist/core/turns/segments/burst-summary.js +24 -0
- package/dist/core/turns/segments/group-steps.d.ts +4 -3
- package/dist/core/turns/segments/group-steps.js +9 -6
- package/dist/core/turns/segments/index.d.ts +1 -0
- package/dist/core/turns/segments/index.js +1 -0
- package/dist/core/turns/segments/narration.d.ts +5 -4
- package/dist/core/turns/segments/narration.js +12 -3
- package/dist/core/turns/segments/session-activity-groups.d.ts +2 -1
- package/dist/core/turns/segments/session-activity-groups.js +3 -1
- package/dist/core/turns/segments/step-label.d.ts +2 -1
- package/dist/core/turns/segments/step-label.js +3 -1
- package/dist/core/turns/segments/work-split.d.ts +10 -0
- package/dist/core/turns/segments/work-split.js +40 -0
- package/dist/core/turns/segments/working-turn.d.ts +4 -2
- package/dist/core/turns/segments/working-turn.js +9 -8
- package/dist/core/turns/state.d.ts +2 -7
- package/dist/core/turns/state.js +28 -134
- package/dist/core/turns/tool-kind.d.ts +1 -1
- package/dist/core/turns/tool-kind.js +3 -2
- package/dist/core/turns/tool-registry.js +1 -0
- package/dist/core/turns/tools/tool-meta.d.ts +3 -2
- package/dist/core/turns/tools/tool-meta.js +5 -2
- package/dist/core/turns/tools/tool-outcome.d.ts +2 -1
- package/dist/core/turns/tools/tool-outcome.js +3 -1
- package/dist/core/turns/types.d.ts +1 -1
- package/dist/core/turns/view-model.js +1 -13
- package/dist/core/warm-session-pool.d.ts +29 -0
- package/dist/core/warm-session-pool.js +127 -0
- package/dist/genui/catalog.d.ts +28 -0
- package/dist/genui/catalog.js +396 -0
- package/dist/genui/expansion.d.ts +3 -0
- package/dist/genui/expansion.js +295 -0
- package/dist/genui/fence-entry.d.ts +2 -0
- package/dist/genui/fence-entry.js +1 -0
- package/dist/genui/fence.d.ts +21 -0
- package/dist/genui/fence.js +138 -0
- package/dist/genui/index.d.ts +6 -0
- package/dist/genui/index.js +6 -0
- package/dist/genui/markdown.d.ts +12 -0
- package/dist/genui/markdown.js +104 -0
- package/dist/genui/parse.d.ts +6 -0
- package/dist/genui/parse.js +75 -0
- package/dist/genui/prompt.d.ts +2 -0
- package/dist/genui/prompt.js +206 -0
- package/dist/genui/react/default-components.d.ts +2 -0
- package/dist/genui/react/default-components.js +72 -0
- package/dist/genui/react/default-components.test.d.ts +1 -0
- package/dist/genui/react/default-components.test.js +94 -0
- package/dist/genui/react/genui-block-disabled.test.d.ts +1 -0
- package/dist/genui/react/genui-block-disabled.test.js +50 -0
- package/dist/genui/react/genui-block.d.ts +28 -0
- package/dist/genui/react/genui-block.js +91 -0
- package/dist/genui/react/genui-block.test.d.ts +1 -0
- package/dist/genui/react/genui-block.test.js +205 -0
- package/dist/genui/react/index.d.ts +2 -0
- package/dist/genui/react/index.js +2 -0
- package/dist/genui/share.d.ts +5 -0
- package/dist/genui/share.js +30 -0
- package/dist/genui/test-fixtures.d.ts +2 -0
- package/dist/genui/test-fixtures.js +16 -0
- package/dist/genui/types.d.ts +29 -0
- package/dist/genui/types.js +1 -0
- package/dist/genui/urls.d.ts +1 -0
- package/dist/genui/urls.js +18 -0
- package/dist/genui/validate.d.ts +9 -0
- package/dist/genui/validate.js +116 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/internal/connector-catalog.d.ts +48 -0
- package/dist/internal/connector-catalog.js +27 -0
- package/dist/internal/host-configuration.d.ts +22 -0
- package/dist/internal/host-configuration.js +28 -0
- package/dist/internal/platform-admin-react.d.ts +12 -0
- package/dist/internal/platform-admin-react.js +13 -0
- package/dist/internal/platform-admin.d.ts +9 -0
- package/dist/internal/platform-admin.js +9 -0
- package/dist/platform/ui.d.ts +8 -2
- package/dist/platform/ui.js +19 -4
- package/dist/react/chat/use-chat-turns.d.ts +1 -1
- package/dist/react/human-presence.d.ts +9 -0
- package/dist/react/human-presence.js +12 -0
- package/dist/react/index.d.ts +4 -13
- package/dist/react/index.js +4 -13
- package/dist/react/opencode.d.ts +1 -0
- package/dist/react/opencode.js +1 -0
- package/dist/react/query-contracts.d.ts +6 -0
- package/dist/react/query-contracts.js +6 -0
- package/dist/react/query-keys.d.ts +17 -2
- package/dist/react/query-keys.js +24 -2
- package/dist/react/reset-identity-state.js +2 -0
- package/dist/react/session-cache-write.d.ts +1 -0
- package/dist/react/session-cache-write.js +20 -0
- package/dist/react/session-transcript-subscription.js +3 -1
- package/dist/react/sign-in-with-beeuni.d.ts +6 -6
- package/dist/react/turn-end-handoff.d.ts +13 -0
- package/dist/react/turn-end-handoff.js +101 -0
- package/dist/react/use-admin-providers.d.ts +3 -6
- package/dist/react/use-admin-providers.js +1 -11
- package/dist/react/use-capture.d.ts +47 -0
- package/dist/react/use-capture.js +173 -0
- package/dist/react/use-feature-flag.js +1 -0
- package/dist/react/use-opencode-events/handle-event.d.ts +1 -0
- package/dist/react/use-opencode-events/handle-event.js +5 -0
- package/dist/react/use-opencode-events/handle-interaction-event.js +8 -3
- package/dist/react/use-opencode-events/handle-session-event.js +13 -8
- package/dist/react/use-opencode-events/handler-context.d.ts +1 -0
- package/dist/react/use-opencode-events/helpers.d.ts +1 -0
- package/dist/react/use-opencode-events/helpers.js +11 -1
- package/dist/react/use-opencode-events/index.js +1 -0
- package/dist/react/use-opencode-local.d.ts +5 -1
- package/dist/react/use-opencode-local.js +15 -2
- package/dist/react/use-opencode-sessions/commands.d.ts +11 -1
- package/dist/react/use-opencode-sessions/commands.js +21 -1
- package/dist/react/use-opencode-sessions/permissions.js +28 -1
- package/dist/react/use-project-sessions.d.ts +1 -1
- package/dist/react/use-project-sessions.js +6 -5
- package/dist/react/use-prompt-attachments.js +1 -0
- package/dist/react/use-review-summary.d.ts +13 -0
- package/dist/react/use-review-summary.js +32 -0
- package/dist/react/use-runtime-reconnect.js +1 -1
- package/dist/react/use-session-list-state.d.ts +6 -0
- package/dist/react/use-session-list-state.js +33 -0
- package/dist/react/use-session-log.d.ts +16 -0
- package/dist/react/use-session-log.js +143 -0
- package/dist/react/use-session-messages.d.ts +2 -1
- package/dist/react/use-session-messages.js +15 -14
- package/dist/react/use-session-stream.js +12 -1
- package/dist/react/use-session-sync.d.ts +2 -2
- package/dist/react/use-session-sync.js +10 -8
- package/dist/react/use-session-transcript-history.js +2 -12
- package/dist/react/use-session-working.d.ts +2 -0
- package/dist/react/use-session-working.js +10 -0
- package/dist/react/use-session.d.ts +6 -0
- package/dist/react/use-session.js +88 -6
- package/package.json +62 -8
package/dist/core/turns/state.js
CHANGED
|
@@ -185,145 +185,39 @@ export function formatDuration(ms) {
|
|
|
185
185
|
const secs = seconds % 60;
|
|
186
186
|
return secs > 0 ? `${minutes}m ${secs}s` : `${minutes}m`;
|
|
187
187
|
}
|
|
188
|
-
export
|
|
189
|
-
|
|
190
|
-
if (!tokens)
|
|
191
|
-
return 0;
|
|
192
|
-
const input = tokens.input ?? 0;
|
|
193
|
-
const output = (tokens.output ?? 0) + (tokens.reasoning ?? 0);
|
|
194
|
-
const cacheRead = tokens.cache?.read ?? 0;
|
|
195
|
-
const cacheWrite = tokens.cache?.write ?? 0;
|
|
196
|
-
const regularInput = Math.max(0, input - cacheRead - cacheWrite);
|
|
197
|
-
const tierCandidates = [
|
|
198
|
-
...(rates.tiers ?? []),
|
|
199
|
-
...(rates.contextOver200k ? [rates.contextOver200k] : []),
|
|
200
|
-
]
|
|
201
|
-
.filter((tier) => input > tier.contextThreshold)
|
|
202
|
-
.sort((a, b) => b.contextThreshold - a.contextThreshold);
|
|
203
|
-
const effective = tierCandidates[0] ?? rates;
|
|
204
|
-
let cost = (regularInput / 1_000_000) * effective.inputPer1M;
|
|
205
|
-
cost += (output / 1_000_000) * effective.outputPer1M;
|
|
206
|
-
if (cacheRead > 0) {
|
|
207
|
-
cost += (cacheRead / 1_000_000) * (effective.cacheReadPer1M ?? effective.inputPer1M);
|
|
208
|
-
}
|
|
209
|
-
if (cacheWrite > 0) {
|
|
210
|
-
cost += (cacheWrite / 1_000_000) * (effective.cacheWritePer1M ?? effective.inputPer1M);
|
|
211
|
-
}
|
|
212
|
-
return cost;
|
|
213
|
-
}
|
|
214
|
-
function isSubscriptionUsage(providerID, modelID) {
|
|
215
|
-
return (providerID === 'codex' ||
|
|
216
|
-
providerID === 'openai-codex' ||
|
|
217
|
-
(providerID === 'beeuni' && !!modelID?.startsWith('codex/')));
|
|
218
|
-
}
|
|
219
|
-
function stepFinishRawCost(sfp, providerID, modelID, lookup) {
|
|
220
|
-
if (isSubscriptionUsage(providerID, modelID))
|
|
221
|
-
return 0;
|
|
222
|
-
const reported = sfp.cost || 0;
|
|
223
|
-
if (reported > 0)
|
|
224
|
-
return reported;
|
|
225
|
-
if (!lookup || !providerID || !modelID)
|
|
226
|
-
return 0;
|
|
227
|
-
const rates = lookup(providerID, modelID);
|
|
228
|
-
if (!rates)
|
|
229
|
-
return 0;
|
|
230
|
-
return estimateTokenCost(sfp.tokens, rates);
|
|
231
|
-
}
|
|
232
|
-
function assistantMessageIds(message) {
|
|
233
|
-
if (message.role !== 'assistant')
|
|
234
|
-
return {};
|
|
235
|
-
const assistant = message;
|
|
236
|
-
return { providerID: assistant.providerID, modelID: assistant.modelID };
|
|
237
|
-
}
|
|
238
|
-
export function getTurnCost(parts, lookup) {
|
|
239
|
-
let totalCost = 0;
|
|
240
|
-
let input = 0;
|
|
241
|
-
let output = 0;
|
|
242
|
-
let reasoning = 0;
|
|
243
|
-
let cacheRead = 0;
|
|
244
|
-
let cacheWrite = 0;
|
|
188
|
+
export function getTurnTokens(parts) {
|
|
189
|
+
const tokens = { input: 0, output: 0, reasoning: 0, cacheRead: 0, cacheWrite: 0 };
|
|
245
190
|
let found = false;
|
|
191
|
+
const add = (usage) => {
|
|
192
|
+
found = true;
|
|
193
|
+
tokens.input += usage.input ?? 0;
|
|
194
|
+
tokens.output += usage.output ?? 0;
|
|
195
|
+
tokens.reasoning += usage.reasoning ?? 0;
|
|
196
|
+
tokens.cacheRead += usage.cache?.read ?? 0;
|
|
197
|
+
tokens.cacheWrite += usage.cache?.write ?? 0;
|
|
198
|
+
};
|
|
199
|
+
const stepMessages = new Set();
|
|
246
200
|
for (const { part, message } of parts) {
|
|
247
|
-
if (part.type
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
reasoning += sfp.tokens?.reasoning || 0;
|
|
255
|
-
cacheRead += sfp.tokens?.cache?.read || 0;
|
|
256
|
-
cacheWrite += sfp.tokens?.cache?.write || 0;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (!found) {
|
|
260
|
-
const seen = new Set();
|
|
261
|
-
for (const { message } of parts) {
|
|
262
|
-
if (message.info.role !== 'assistant')
|
|
263
|
-
continue;
|
|
264
|
-
const assistant = message.info;
|
|
265
|
-
if (seen.has(assistant.id))
|
|
266
|
-
continue;
|
|
267
|
-
seen.add(assistant.id);
|
|
268
|
-
const stepCost = assistantTokensCost(assistant, lookup);
|
|
269
|
-
const subscriptionTokens = assistant.tokens && isSubscriptionUsage(assistant.providerID, assistant.modelID);
|
|
270
|
-
if (stepCost <= 0 && !subscriptionTokens)
|
|
271
|
-
continue;
|
|
272
|
-
found = true;
|
|
273
|
-
totalCost += stepCost;
|
|
274
|
-
const t = assistant.tokens;
|
|
275
|
-
if (t) {
|
|
276
|
-
input += t.input ?? 0;
|
|
277
|
-
output += t.output ?? 0;
|
|
278
|
-
reasoning += t.reasoning ?? 0;
|
|
279
|
-
cacheRead += t.cache?.read ?? 0;
|
|
280
|
-
cacheWrite += t.cache?.write ?? 0;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
201
|
+
if (part.type !== 'step-finish')
|
|
202
|
+
continue;
|
|
203
|
+
const usage = part.tokens;
|
|
204
|
+
if (!usage)
|
|
205
|
+
continue;
|
|
206
|
+
stepMessages.add(message.info.id);
|
|
207
|
+
add(usage);
|
|
283
208
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
function assistantTokensCost(assistant, lookup) {
|
|
292
|
-
if (isSubscriptionUsage(assistant.providerID, assistant.modelID))
|
|
293
|
-
return 0;
|
|
294
|
-
if (!lookup || !assistant.providerID || !assistant.modelID || !assistant.tokens)
|
|
295
|
-
return 0;
|
|
296
|
-
const rates = lookup(assistant.providerID, assistant.modelID);
|
|
297
|
-
if (!rates)
|
|
298
|
-
return 0;
|
|
299
|
-
return estimateTokenCost({
|
|
300
|
-
input: assistant.tokens.input,
|
|
301
|
-
output: assistant.tokens.output,
|
|
302
|
-
reasoning: assistant.tokens.reasoning,
|
|
303
|
-
cache: assistant.tokens.cache,
|
|
304
|
-
}, rates);
|
|
305
|
-
}
|
|
306
|
-
export function getSessionCost(messages, lookup) {
|
|
307
|
-
let totalCost = 0;
|
|
308
|
-
for (const msg of messages) {
|
|
309
|
-
if (msg.info?.role !== 'assistant')
|
|
209
|
+
const seen = new Set();
|
|
210
|
+
for (const { message } of parts) {
|
|
211
|
+
if (message.info.role !== 'assistant' ||
|
|
212
|
+
stepMessages.has(message.info.id) ||
|
|
213
|
+
seen.has(message.info.id))
|
|
310
214
|
continue;
|
|
311
|
-
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
for (const part of msg.parts) {
|
|
316
|
-
if (part.type !== 'step-finish')
|
|
317
|
-
continue;
|
|
318
|
-
sawStepFinish = true;
|
|
319
|
-
msgCost += stepFinishRawCost(part, providerID, modelID, lookup);
|
|
320
|
-
}
|
|
321
|
-
if (!sawStepFinish) {
|
|
322
|
-
msgCost += assistantTokensCost(assistant, lookup);
|
|
323
|
-
}
|
|
324
|
-
totalCost += msgCost;
|
|
215
|
+
seen.add(message.info.id);
|
|
216
|
+
const usage = message.info.tokens;
|
|
217
|
+
if (usage)
|
|
218
|
+
add(usage);
|
|
325
219
|
}
|
|
326
|
-
return
|
|
220
|
+
return found ? tokens : undefined;
|
|
327
221
|
}
|
|
328
222
|
export function formatCost(cost) {
|
|
329
223
|
if (cost === 0)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type ToolKind = 'read' | 'list' | 'glob' | 'grep' | 'write' | 'edit' | 'apply_patch' | 'bash' | 'pty' | 'web_search' | 'webfetch' | 'media' | 'show' | 'task' | 'delegate' | 'sessions' | 'todowrite' | 'question' | 'memory' | 'connectors' | 'automations' | 'projects' | 'skill' | 'context' | 'retired' | 'other';
|
|
1
|
+
export type ToolKind = 'read' | 'list' | 'glob' | 'grep' | 'write' | 'edit' | 'apply_patch' | 'bash' | 'pty' | 'script' | 'web_search' | 'webfetch' | 'media' | 'show' | 'task' | 'delegate' | 'sessions' | 'todowrite' | 'question' | 'memory' | 'connectors' | 'automations' | 'projects' | 'skill' | 'context' | 'retired' | 'other';
|
|
2
2
|
export declare function toolKind(name: string): ToolKind;
|
|
3
3
|
export declare function inputPath(input: Record<string, unknown> | undefined): string | undefined;
|
|
@@ -8,9 +8,10 @@ kind('list', ['list', 'ls']);
|
|
|
8
8
|
kind('glob', ['glob']);
|
|
9
9
|
kind('grep', ['grep']);
|
|
10
10
|
kind('write', ['write']);
|
|
11
|
-
kind('edit', ['edit', 'multiedit', 'morph_edit']);
|
|
11
|
+
kind('edit', ['edit', 'multiedit', 'morph_edit', 'MultiEdit', 'NotebookEdit']);
|
|
12
12
|
kind('apply_patch', ['apply_patch', 'patch']);
|
|
13
13
|
kind('bash', ['bash']);
|
|
14
|
+
kind('script', ['codemode']);
|
|
14
15
|
kind('web_search', ['web_search', 'websearch', 'image_search']);
|
|
15
16
|
kind('webfetch', ['webfetch', 'web_fetch', 'scrape_webpage', 'scrapewebpage']);
|
|
16
17
|
kind('media', ['image_gen', 'video_gen']);
|
|
@@ -91,7 +92,7 @@ export function toolKind(name) {
|
|
|
91
92
|
return 'other';
|
|
92
93
|
}
|
|
93
94
|
export function inputPath(input) {
|
|
94
|
-
for (const value of [input?.filePath, input?.file_path, input?.path]) {
|
|
95
|
+
for (const value of [input?.filePath, input?.file_path, input?.path, input?.notebook_path]) {
|
|
95
96
|
if (typeof value === 'string' && value)
|
|
96
97
|
return value;
|
|
97
98
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ToolPart } from '../../runtime/client.js';
|
|
2
|
+
import type { ToolCallBlock } from '../../session-log/types.js';
|
|
2
3
|
export declare const CONTEXT_TOOLS: Set<string>;
|
|
3
4
|
export declare function normalizeName(name: string): string;
|
|
4
5
|
export declare function isContextTool(toolName: string): boolean;
|
|
@@ -7,7 +8,7 @@ export declare function contextToolSummary(parts: ToolPart[]): {
|
|
|
7
8
|
search: number;
|
|
8
9
|
list: number;
|
|
9
10
|
};
|
|
10
|
-
export declare function getToolPrimaryArg(
|
|
11
|
+
export declare function getToolPrimaryArg(call: ToolPart | ToolCallBlock): string;
|
|
11
12
|
export interface ContextToolTriggerLabels {
|
|
12
13
|
read: string;
|
|
13
14
|
search: string;
|
|
@@ -24,7 +25,7 @@ export interface ContextToolTriggerLabels {
|
|
|
24
25
|
workspace: string;
|
|
25
26
|
}
|
|
26
27
|
export declare const DEFAULT_CONTEXT_TOOL_TRIGGER_LABELS: Readonly<ContextToolTriggerLabels>;
|
|
27
|
-
export declare function contextToolTrigger(
|
|
28
|
+
export declare function contextToolTrigger(call: ToolPart | ToolCallBlock, labels?: Partial<ContextToolTriggerLabels>): {
|
|
28
29
|
title: string;
|
|
29
30
|
subtitle: string;
|
|
30
31
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { toolKind } from '../tool-kind.js';
|
|
2
|
+
import { asToolPart, isToolCallBlock, toolPartOf } from '../../session-log/tool-call.js';
|
|
2
3
|
import { humanizeSearchQuery } from './search-query.js';
|
|
3
4
|
import { stripTrailingSlashes } from '../text-scan.js';
|
|
4
5
|
export const CONTEXT_TOOLS = new Set(['read', 'glob', 'grep', 'list']);
|
|
@@ -36,7 +37,8 @@ function truncate(s, max = 60) {
|
|
|
36
37
|
const trimmed = s.replace(/\s+/g, ' ').trim();
|
|
37
38
|
return trimmed.length > max ? `${trimmed.slice(0, max)}…` : trimmed;
|
|
38
39
|
}
|
|
39
|
-
export function getToolPrimaryArg(
|
|
40
|
+
export function getToolPrimaryArg(call) {
|
|
41
|
+
const part = asToolPart(call);
|
|
40
42
|
const state = (part.state ?? {});
|
|
41
43
|
const input = (state.input ?? {});
|
|
42
44
|
const key = normalizeName(part.tool);
|
|
@@ -100,7 +102,8 @@ export const DEFAULT_CONTEXT_TOOL_TRIGGER_LABELS = {
|
|
|
100
102
|
worker: 'Worker',
|
|
101
103
|
workspace: 'Workspace',
|
|
102
104
|
};
|
|
103
|
-
export function contextToolTrigger(
|
|
105
|
+
export function contextToolTrigger(call, labels = {}) {
|
|
106
|
+
const part = isToolCallBlock(call) ? toolPartOf(call) : call;
|
|
104
107
|
const l = { ...DEFAULT_CONTEXT_TOOL_TRIGGER_LABELS, ...labels };
|
|
105
108
|
const n = normalizeName(part.tool);
|
|
106
109
|
const sub = getToolPrimaryArg(part);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ToolPart } from '../../runtime/client.js';
|
|
2
|
+
import type { ToolCallBlock } from '../../session-log/types.js';
|
|
2
3
|
export interface ParsedJsonFailure {
|
|
3
4
|
errorSummary: string;
|
|
4
5
|
hint?: string;
|
|
@@ -9,7 +10,7 @@ export interface ParsedJsonFailure {
|
|
|
9
10
|
export type ToolOutcome = 'ok' | 'partial' | 'failed';
|
|
10
11
|
export declare function looksLikeError(text: string): boolean;
|
|
11
12
|
export declare function isErrorOutput(output: string): boolean;
|
|
12
|
-
export declare function partOutcome(
|
|
13
|
+
export declare function partOutcome(call: Pick<ToolPart, 'state'> | ToolCallBlock): ToolOutcome;
|
|
13
14
|
export declare function parseJsonFailure(output: string): ParsedJsonFailure | null;
|
|
14
15
|
export declare function cleanErrorMessage(raw: string): string;
|
|
15
16
|
export declare function formatJsonFailureOutput(output: string): string | null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsonTail, stripErrorPrefixes } from '../text-scan.js';
|
|
2
|
+
import { isToolCallBlock, toolPartOf } from '../../session-log/tool-call.js';
|
|
2
3
|
function isJsonObject(value) {
|
|
3
4
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
4
5
|
}
|
|
@@ -19,7 +20,8 @@ export function looksLikeError(text) {
|
|
|
19
20
|
export function isErrorOutput(output) {
|
|
20
21
|
return !!output && (looksLikeError(output) || parseJsonFailure(output) !== null);
|
|
21
22
|
}
|
|
22
|
-
export function partOutcome(
|
|
23
|
+
export function partOutcome(call) {
|
|
24
|
+
const part = isToolCallBlock(call) ? toolPartOf(call) : call;
|
|
23
25
|
const cached = OUTCOME_CACHE.get(part);
|
|
24
26
|
if (cached && cached.state === part.state)
|
|
25
27
|
return cached.outcome;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { editBlocks } from './edit-blocks.js';
|
|
1
2
|
import { toolKind } from './tool-kind.js';
|
|
2
3
|
const PRETTY_CAP = 4000;
|
|
3
4
|
function capText(text, max = PRETTY_CAP) {
|
|
@@ -144,19 +145,6 @@ function computeLineDiff(oldStr, newStr) {
|
|
|
144
145
|
lines.push({ type: 'unchanged', text: oldLines[i] });
|
|
145
146
|
return lines;
|
|
146
147
|
}
|
|
147
|
-
function editBlocks(input) {
|
|
148
|
-
const oldString = firstString(input?.oldString);
|
|
149
|
-
const newString = firstString(input?.newString);
|
|
150
|
-
if (oldString !== undefined && newString !== undefined)
|
|
151
|
-
return [[oldString, newString]];
|
|
152
|
-
const edits = Array.isArray(input?.edits) ? input.edits : [];
|
|
153
|
-
return edits.flatMap((edit) => {
|
|
154
|
-
const e = asRecord(edit);
|
|
155
|
-
const before = e && firstString(e.oldText);
|
|
156
|
-
const after = e && firstString(e.newText);
|
|
157
|
-
return before !== undefined && after !== undefined ? [[before, after]] : [];
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
148
|
function fileEditViewModel(tool) {
|
|
161
149
|
const blocks = editBlocks(tool.input);
|
|
162
150
|
const diffs = blocks.map(([before, after]) => computeLineDiff(before, after));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface WarmPoolSession {
|
|
2
|
+
sessionId: string;
|
|
3
|
+
}
|
|
4
|
+
export interface WarmSessionPoolClient<Session extends WarmPoolSession, ClaimInput> {
|
|
5
|
+
ensure: (projectId: string, excludeSessionId?: string) => Promise<Session>;
|
|
6
|
+
claim: (projectId: string, input: ClaimInput) => Promise<unknown>;
|
|
7
|
+
read: (projectId: string, sessionId: string) => Promise<{
|
|
8
|
+
metadata?: unknown;
|
|
9
|
+
} | null>;
|
|
10
|
+
}
|
|
11
|
+
export interface WarmSessionPoolCoreOptions<Session extends WarmPoolSession, Send> {
|
|
12
|
+
fits: (session: Session, send: Send) => boolean;
|
|
13
|
+
sleep?: (ms: number) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export interface WarmSessionPoolCore<Session extends WarmPoolSession, Send, ClaimInput> {
|
|
16
|
+
ensure: (projectId: string, options?: {
|
|
17
|
+
excludeSessionId?: string;
|
|
18
|
+
}) => Promise<void>;
|
|
19
|
+
take: (projectId: string, send: Send, options: {
|
|
20
|
+
replenish: boolean;
|
|
21
|
+
}) => Session | null;
|
|
22
|
+
prime: (projectId: string, session: Session, input: ClaimInput) => Promise<boolean>;
|
|
23
|
+
dropBySessionId: (sessionId: string) => string | null;
|
|
24
|
+
revalidate: (projectId: string) => Promise<boolean>;
|
|
25
|
+
held: (projectId: string) => Session | null;
|
|
26
|
+
reset: () => void;
|
|
27
|
+
settled: () => Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export declare function createWarmSessionPool<Session extends WarmPoolSession, Send, ClaimInput>(client: WarmSessionPoolClient<Session, ClaimInput>, options: WarmSessionPoolCoreOptions<Session, Send>): WarmSessionPoolCore<Session, Send, ClaimInput>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
function isAmbiguousCreateFailure(code) {
|
|
2
|
+
return code === 'TIMEOUT' || code === 'request_deadline';
|
|
3
|
+
}
|
|
4
|
+
function errorCode(error) {
|
|
5
|
+
const code = isRecord(error) ? error.code : undefined;
|
|
6
|
+
return typeof code === 'string' ? code : undefined;
|
|
7
|
+
}
|
|
8
|
+
const isRecord = (value) => typeof value === 'object' && value !== null;
|
|
9
|
+
function isWarmRow(row) {
|
|
10
|
+
const metadata = row?.metadata;
|
|
11
|
+
return !!isRecord(metadata) && metadata.warm === true;
|
|
12
|
+
}
|
|
13
|
+
const COMMIT_CONFIRM_ATTEMPTS = 5;
|
|
14
|
+
const COMMIT_CONFIRM_DELAY_MS = 2_000;
|
|
15
|
+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
16
|
+
async function confirmCommitted(probe, { attempts = COMMIT_CONFIRM_ATTEMPTS, delayMs = COMMIT_CONFIRM_DELAY_MS, sleep = wait, } = {}) {
|
|
17
|
+
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
18
|
+
if (attempt > 0)
|
|
19
|
+
await sleep(delayMs);
|
|
20
|
+
try {
|
|
21
|
+
if (await probe())
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
export function createWarmSessionPool(client, options) {
|
|
30
|
+
const ready = new Map();
|
|
31
|
+
const creating = new Set();
|
|
32
|
+
const taken = new Set();
|
|
33
|
+
const inFlight = new Set();
|
|
34
|
+
let generation = 0;
|
|
35
|
+
const runEnsure = (projectId, excludeSessionId, retriesLeft) => {
|
|
36
|
+
if (creating.has(projectId) || ready.has(projectId))
|
|
37
|
+
return Promise.resolve();
|
|
38
|
+
creating.add(projectId);
|
|
39
|
+
const startedIn = generation;
|
|
40
|
+
const run = (async () => {
|
|
41
|
+
let retryExclude = null;
|
|
42
|
+
try {
|
|
43
|
+
const session = await client.ensure(projectId, excludeSessionId);
|
|
44
|
+
if (startedIn !== generation)
|
|
45
|
+
return;
|
|
46
|
+
if (taken.has(session.sessionId))
|
|
47
|
+
retryExclude = session.sessionId;
|
|
48
|
+
else
|
|
49
|
+
ready.set(projectId, session);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
if (startedIn === generation)
|
|
55
|
+
creating.delete(projectId);
|
|
56
|
+
}
|
|
57
|
+
if (retryExclude && retriesLeft > 0) {
|
|
58
|
+
await runEnsure(projectId, retryExclude, retriesLeft - 1);
|
|
59
|
+
}
|
|
60
|
+
})();
|
|
61
|
+
inFlight.add(run);
|
|
62
|
+
void run.finally(() => inFlight.delete(run));
|
|
63
|
+
return run;
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
ensure: (projectId, opts) => runEnsure(projectId, opts?.excludeSessionId, 1),
|
|
67
|
+
take: (projectId, send, { replenish }) => {
|
|
68
|
+
const warm = ready.get(projectId);
|
|
69
|
+
if (!warm)
|
|
70
|
+
return null;
|
|
71
|
+
ready.delete(projectId);
|
|
72
|
+
taken.add(warm.sessionId);
|
|
73
|
+
if (replenish)
|
|
74
|
+
void runEnsure(projectId, warm.sessionId, 1);
|
|
75
|
+
return options.fits(warm, send) ? warm : null;
|
|
76
|
+
},
|
|
77
|
+
prime: async (projectId, warm, input) => {
|
|
78
|
+
try {
|
|
79
|
+
await client.claim(projectId, input);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (!isAmbiguousCreateFailure(errorCode(error)))
|
|
84
|
+
return false;
|
|
85
|
+
return confirmCommitted(async () => !isWarmRow(await client.read(projectId, warm.sessionId)), options.sleep ? { sleep: options.sleep } : {});
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
dropBySessionId: (sessionId) => {
|
|
89
|
+
for (const [projectId, warm] of ready) {
|
|
90
|
+
if (warm.sessionId !== sessionId)
|
|
91
|
+
continue;
|
|
92
|
+
ready.delete(projectId);
|
|
93
|
+
taken.add(sessionId);
|
|
94
|
+
return projectId;
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
},
|
|
98
|
+
revalidate: async (projectId) => {
|
|
99
|
+
const held = ready.get(projectId);
|
|
100
|
+
if (!held)
|
|
101
|
+
return false;
|
|
102
|
+
try {
|
|
103
|
+
if (isWarmRow(await client.read(projectId, held.sessionId)))
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
if (ready.get(projectId)?.sessionId !== held.sessionId)
|
|
110
|
+
return false;
|
|
111
|
+
ready.delete(projectId);
|
|
112
|
+
taken.add(held.sessionId);
|
|
113
|
+
return true;
|
|
114
|
+
},
|
|
115
|
+
held: (projectId) => ready.get(projectId) ?? null,
|
|
116
|
+
reset: () => {
|
|
117
|
+
generation += 1;
|
|
118
|
+
ready.clear();
|
|
119
|
+
creating.clear();
|
|
120
|
+
taken.clear();
|
|
121
|
+
},
|
|
122
|
+
settled: async () => {
|
|
123
|
+
while (inFlight.size > 0)
|
|
124
|
+
await Promise.all([...inFlight]);
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Library } from '@openuidev/lang-core';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
import type { GenuiNode } from './types.js';
|
|
4
|
+
export interface GenuiSlot {
|
|
5
|
+
accepts: readonly string[];
|
|
6
|
+
min: number;
|
|
7
|
+
max: number;
|
|
8
|
+
optional?: boolean;
|
|
9
|
+
lazy?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type GenuiChildToMarkdown = (node: GenuiNode) => string;
|
|
12
|
+
export interface GenuiComponentSpec {
|
|
13
|
+
name: string;
|
|
14
|
+
block: boolean;
|
|
15
|
+
container: boolean;
|
|
16
|
+
slots: Readonly<Record<string, GenuiSlot>>;
|
|
17
|
+
urls: Readonly<Record<string, 'required' | 'optional'>>;
|
|
18
|
+
strict: z.ZodType;
|
|
19
|
+
streaming: z.ZodType;
|
|
20
|
+
toMarkdown(props: Record<string, any>, child: GenuiChildToMarkdown): string;
|
|
21
|
+
a11y?(props: Record<string, any>): string;
|
|
22
|
+
}
|
|
23
|
+
export declare const GENUI_BLOCKS: readonly ["Stack", "Card", "Stat", "StatRow", "Table", "Compare", "RankedList", "BarChart", "LineChart", "PieChart", "Map", "Steps", "Checklist", "Tabs", "Accordion", "Badge", "Callout", "Image", "Link"];
|
|
24
|
+
export declare const GENUI_SPECS: Readonly<Record<string, GenuiComponentSpec>>;
|
|
25
|
+
export declare const GENUI_LIBRARY: Library<string>;
|
|
26
|
+
export declare const GENUI_MAX_DEPTH = 4;
|
|
27
|
+
export declare const GENUI_MAX_NODES = 500;
|
|
28
|
+
export declare const GENUI_MAX_SOURCE_CHARS: number;
|