@agent-native/core 0.204.0 → 0.204.1-nightly-20261008065100
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/dist/action.js +5 -6
- package/dist/agent/auto-continue.d.ts +35 -0
- package/dist/agent/auto-continue.js +38 -0
- package/dist/agent/connection-required-note.d.ts +52 -0
- package/dist/agent/connection-required-note.js +187 -0
- package/dist/agent/jev-tool-prefetch.d.ts +5 -1
- package/dist/agent/jev-tool-prefetch.js +19 -6
- package/dist/agent/previous-turn-note.d.ts +9 -0
- package/dist/agent/previous-turn-note.js +48 -0
- package/dist/agent/production-agent.d.ts +17 -13
- package/dist/agent/production-agent.js +185 -43
- package/dist/agent/reaped-run-thread.d.ts +13 -0
- package/dist/agent/reaped-run-thread.js +45 -0
- package/dist/agent/run-store.d.ts +29 -5
- package/dist/agent/run-store.js +144 -30
- package/dist/agent/thread-data-builder.d.ts +16 -0
- package/dist/agent/thread-data-builder.js +30 -8
- package/dist/agent/thread-message-projection.js +5 -3
- package/dist/agent/tool-search.js +5 -1
- package/dist/agent/types.d.ts +3 -0
- package/dist/audit/config.d.ts +6 -0
- package/dist/audit/config.js +12 -1
- package/dist/audit/index.d.ts +1 -1
- package/dist/audit/index.js +1 -1
- package/dist/audit/store.js +39 -4
- package/dist/automation/index.d.ts +1 -1
- package/dist/cli/skills.d.ts +1 -0
- package/dist/cli/skills.js +1 -1
- package/dist/client/agent-chat/index.d.ts +1 -1
- package/dist/client/agent-chat/index.js +1 -1
- package/dist/client/chat/agentkit-agent-native.js +83 -7
- package/dist/client/chat/agentkit-protocol.js +140 -67
- package/dist/client/chat/runtime.js +10 -4
- package/dist/client/embed-auth.d.ts +15 -0
- package/dist/client/embed-auth.js +77 -7
- package/dist/client/host/index.d.ts +1 -1
- package/dist/client/host/index.js +1 -1
- package/dist/client/mcp-app-host.d.ts +19 -0
- package/dist/client/mcp-app-host.js +88 -2
- package/dist/client/use-chat-threads.d.ts +1 -1
- package/dist/client/use-chat-threads.js +2 -0
- package/dist/client/use-run-stuck-detection.d.ts +18 -1
- package/dist/client/use-run-stuck-detection.js +115 -75
- package/dist/collab/routes.d.ts +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/db/request-telemetry.d.ts +7 -1
- package/dist/db/request-telemetry.js +20 -1
- package/dist/deploy/build.d.ts +25 -1
- package/dist/deploy/build.js +176 -3
- package/dist/deploy/workspace-deploy.js +8 -3
- package/dist/extensions/fetch-tool.js +50 -14
- package/dist/file-upload/builder.js +1 -1
- package/dist/file-upload/s3.js +1 -1
- package/dist/file-upload/types.d.ts +1 -0
- package/dist/integrations/adapters/email.js +11 -3
- package/dist/integrations/adapters/telegram.js +4 -2
- package/dist/jobs/actions/automation-no-op.d.ts +12 -0
- package/dist/jobs/actions/automation-no-op.js +20 -0
- package/dist/jobs/actions/manage-recurring-job.d.ts +1 -1
- package/dist/jobs/background-automation-runner.d.ts +8 -1
- package/dist/jobs/background-automation-runner.js +102 -19
- package/dist/jobs/run-history.d.ts +1 -1
- package/dist/jobs/run-history.js +8 -4
- package/dist/jobs/scheduler.js +25 -12
- package/dist/localization/automation-outcome-messages.d.ts +22 -0
- package/dist/localization/automation-outcome-messages.js +90 -0
- package/dist/localization/default-messages.d.ts +2 -0
- package/dist/localization/default-messages.js +4 -2
- package/dist/mcp/build-server.js +22 -11
- package/dist/mcp/embed-app.js +143 -9
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/observability/metrics.d.ts +3 -0
- package/dist/observability/metrics.js +10 -0
- package/dist/observability/migrations.js +22 -0
- package/dist/observability/routes.d.ts +10 -5
- package/dist/observability/routes.js +88 -14
- package/dist/observability/sentiment.d.ts +5 -0
- package/dist/observability/sentiment.js +75 -25
- package/dist/observability/store.d.ts +28 -0
- package/dist/observability/store.js +58 -0
- package/dist/observability/traces.js +37 -5
- package/dist/org/handlers.d.ts +1 -1
- package/dist/progress/actions.js +1 -0
- package/dist/provider-api/actions/custom-provider-registration.d.ts +13 -13
- package/dist/provider-api/actions/provider-api.d.ts +13 -13
- package/dist/provider-api/actions/provider-api.js +6 -2
- package/dist/provider-api/index.d.ts +1 -0
- package/dist/provider-api/index.js +18 -0
- package/dist/provider-api/result-outcome.d.ts +1 -0
- package/dist/provider-api/result-outcome.js +20 -0
- package/dist/provider-api/staging.js +10 -9
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/resources/script-helpers.d.ts +1 -0
- package/dist/resources/script-helpers.js +1 -1
- package/dist/resources/store.js +81 -0
- package/dist/scripts/resources/save-memory.js +3 -0
- package/dist/server/action-routes.js +34 -6
- package/dist/server/agent-chat/prompt-resources.d.ts +8 -2
- package/dist/server/agent-chat/prompt-resources.js +31 -8
- package/dist/server/agent-chat/recurring-jobs-runtime.d.ts +19 -4
- package/dist/server/agent-chat/recurring-jobs-runtime.js +52 -16
- package/dist/server/agent-chat/script-entries.js +30 -3
- package/dist/server/agent-chat/sweep-trigger-auth.d.ts +18 -0
- package/dist/server/agent-chat/sweep-trigger-auth.js +36 -0
- package/dist/server/agent-chat-plugin.js +51 -47
- package/dist/server/agent-engine-default-model-route.d.ts +2 -2
- package/dist/server/agent-engine-ollama-models-route.d.ts +2 -2
- package/dist/server/auth.js +21 -6
- package/dist/server/embed-route.js +5 -2
- package/dist/server/framework-request-handler.js +19 -0
- package/dist/server/http-response-telemetry.js +4 -1
- package/dist/server/realtime-token.d.ts +1 -1
- package/dist/server/request-context.d.ts +6 -0
- package/dist/shared/context-status.d.ts +21 -0
- package/dist/shared/context-status.js +54 -0
- package/dist/shared/mcp-app-display.d.ts +20 -0
- package/dist/shared/mcp-app-display.js +34 -0
- package/dist/shared/mcp-app-widget-embed.d.ts +18 -0
- package/dist/shared/mcp-app-widget-embed.js +41 -0
- package/dist/templates/chat/app/components/chat/ChatRouteContent.tsx +9 -2
- package/dist/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +9 -2
- package/dist/templates/workspace-core/.agents/skills/automations/SKILL.md +8 -1
- package/dist/templates/workspace-core/.agents/skills/recurring-jobs/SKILL.md +3 -1
- package/dist/triggers/actions/manage-automation.d.ts +5 -5
- package/dist/triggers/dispatcher.js +10 -7
- package/docs/content/audit-log.mdx +3 -3
- package/docs/content/cloudflare.mdx +27 -0
- package/docs/content/deployment-environment-variables.mdx +2 -0
- package/docs/content/durable-resume.mdx +3 -1
- package/docs/content/environment-variables.mdx +2 -0
- package/docs/content/mcp-apps.mdx +1 -1
- package/docs/content/recurring-jobs.mdx +29 -9
- package/docs/content/vercel.mdx +30 -0
- package/package.json +4 -3
- package/src/templates/chat/app/components/chat/ChatRouteContent.tsx +9 -2
- package/src/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +9 -2
- package/src/templates/workspace-core/.agents/skills/automations/SKILL.md +8 -1
- package/src/templates/workspace-core/.agents/skills/recurring-jobs/SKILL.md +3 -1
|
@@ -99,19 +99,35 @@ function truncateInput(text) {
|
|
|
99
99
|
.slice(0, INFERRED_SENTIMENT_MAX_CHARS)
|
|
100
100
|
.join("");
|
|
101
101
|
}
|
|
102
|
+
export const INFERRED_SENTIMENT_FAILURE_REASONS = [
|
|
103
|
+
"engine_unavailable",
|
|
104
|
+
"timeout",
|
|
105
|
+
"parse_failed",
|
|
106
|
+
"empty",
|
|
107
|
+
];
|
|
108
|
+
function engineCanRun(engine, model) {
|
|
109
|
+
return (engine.preserveCustomModels === true ||
|
|
110
|
+
engine.supportedModels.length === 0 ||
|
|
111
|
+
engine.supportedModels.includes(model));
|
|
112
|
+
}
|
|
102
113
|
async function classifySentiment(args) {
|
|
103
|
-
if (!args.engine.
|
|
104
|
-
|
|
105
|
-
!args.engine.supportedModels.includes(args.model)) {
|
|
106
|
-
return null;
|
|
114
|
+
if (!engineCanRun(args.engine, args.model)) {
|
|
115
|
+
return { failure: "engine_unavailable" };
|
|
107
116
|
}
|
|
108
117
|
const input = truncateInput(args.text);
|
|
109
118
|
if (!input)
|
|
110
|
-
return
|
|
119
|
+
return { failure: "empty" };
|
|
111
120
|
const controller = new AbortController();
|
|
112
|
-
|
|
121
|
+
let timedOut = false;
|
|
122
|
+
const timeout = setTimeout(() => {
|
|
123
|
+
timedOut = true;
|
|
124
|
+
controller.abort();
|
|
125
|
+
}, INFERRED_SENTIMENT_TIMEOUT_MS);
|
|
113
126
|
let output = "";
|
|
114
127
|
let finalOutput = "";
|
|
128
|
+
const interrupted = () => ({
|
|
129
|
+
failure: timedOut ? "timeout" : "engine_unavailable",
|
|
130
|
+
});
|
|
115
131
|
try {
|
|
116
132
|
for await (const event of args.engine.stream({
|
|
117
133
|
model: args.model,
|
|
@@ -133,51 +149,85 @@ async function classifySentiment(args) {
|
|
|
133
149
|
.join("");
|
|
134
150
|
}
|
|
135
151
|
if (typedEvent.type === "stop" && typedEvent.reason === "error") {
|
|
136
|
-
return
|
|
152
|
+
return interrupted();
|
|
137
153
|
}
|
|
138
154
|
}
|
|
139
|
-
return parseInferredSentiment(finalOutput || output);
|
|
140
155
|
}
|
|
141
156
|
catch {
|
|
142
|
-
return
|
|
157
|
+
return interrupted();
|
|
143
158
|
}
|
|
144
159
|
finally {
|
|
145
160
|
clearTimeout(timeout);
|
|
146
161
|
}
|
|
162
|
+
// An aborted stream can end quietly; its partial text is not a verdict.
|
|
163
|
+
if (timedOut)
|
|
164
|
+
return { failure: "timeout" };
|
|
165
|
+
const verdict = (finalOutput || output).trim();
|
|
166
|
+
if (!verdict)
|
|
167
|
+
return { failure: "empty" };
|
|
168
|
+
const sentiment = parseInferredSentiment(verdict);
|
|
169
|
+
return sentiment ? { sentiment } : { failure: "parse_failed" };
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The run's own engine when it can serve the classifier model, so a Builder run
|
|
173
|
+
* classifies with the credentials it already holds. Otherwise the hosted
|
|
174
|
+
* Builder engine; `null` when that cannot even be constructed.
|
|
175
|
+
*/
|
|
176
|
+
async function resolveClassifierEngine(args) {
|
|
177
|
+
if (args.engine)
|
|
178
|
+
return args.engine;
|
|
179
|
+
if (args.runEngine && engineCanRun(args.runEngine, args.classifierModel)) {
|
|
180
|
+
return args.runEngine;
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
return (await import("../agent/engine/builder-engine.js")).createBuilderEngine();
|
|
184
|
+
// coercion-ok: the caller reports a null engine as `engine_unavailable`.
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
147
189
|
}
|
|
148
190
|
export async function inferAndTrackSentiment(args) {
|
|
149
191
|
try {
|
|
150
192
|
if (!shouldSampleInferredSentiment(args.classificationTriggerRunId, args.sampleRate)) {
|
|
151
193
|
return;
|
|
152
194
|
}
|
|
153
|
-
const engine = args
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return;
|
|
195
|
+
const engine = await resolveClassifierEngine(args);
|
|
196
|
+
const result = engine
|
|
197
|
+
? await classifySentiment({
|
|
198
|
+
engine,
|
|
199
|
+
model: args.classifierModel,
|
|
200
|
+
text: args.text,
|
|
201
|
+
})
|
|
202
|
+
: { failure: "engine_unavailable" };
|
|
162
203
|
const { track } = await import("../tracking/registry.js");
|
|
163
|
-
|
|
204
|
+
const shared = {
|
|
164
205
|
...trackingIdentityProperties(),
|
|
165
206
|
source: "agent_observability",
|
|
166
207
|
method: "llm",
|
|
167
|
-
sentiment,
|
|
168
208
|
model: args.precedingResponseModel,
|
|
169
209
|
classifier_model: args.classifierModel,
|
|
170
|
-
classifier_engine: engine
|
|
171
|
-
attribution: "user_reaction_to_preceding_model",
|
|
210
|
+
classifier_engine: engine?.name,
|
|
172
211
|
run_id: args.precedingRunId,
|
|
173
212
|
classification_trigger_run_id: args.classificationTriggerRunId,
|
|
174
213
|
thread_id: args.threadId,
|
|
175
214
|
$ai_model: args.precedingResponseModel,
|
|
176
215
|
$ai_trace_id: args.precedingRunId,
|
|
177
216
|
$ai_session_id: args.threadId ?? undefined,
|
|
178
|
-
}
|
|
217
|
+
};
|
|
218
|
+
// A classifier that fails must show up as a count, never as a quiet drop
|
|
219
|
+
// in `$ai_sentiment`; the reason is coarse and carries no message content.
|
|
220
|
+
track("failure" in result ? "$ai_sentiment_failed" : "$ai_sentiment", "failure" in result
|
|
221
|
+
? { ...shared, reason: result.failure }
|
|
222
|
+
: {
|
|
223
|
+
...shared,
|
|
224
|
+
sentiment: result.sentiment,
|
|
225
|
+
attribution: "user_reaction_to_preceding_model",
|
|
226
|
+
}, { userId: args.userId ?? undefined });
|
|
179
227
|
}
|
|
180
|
-
catch {
|
|
181
|
-
//
|
|
228
|
+
catch (error) {
|
|
229
|
+
// Optional inference must never affect chat, but an unexpected failure
|
|
230
|
+
// outside the classifier must not vanish either.
|
|
231
|
+
console.warn("[agent-native] observability: sentiment inference failed", error instanceof Error ? error.message : String(error));
|
|
182
232
|
}
|
|
183
233
|
}
|
|
@@ -48,6 +48,34 @@ export declare function getTraceSummary(runId: string, opts?: {
|
|
|
48
48
|
userId?: string;
|
|
49
49
|
orgId?: string;
|
|
50
50
|
}): Promise<TraceSummary | null>;
|
|
51
|
+
/**
|
|
52
|
+
* A thread created on a path with no request org keeps `org_id` NULL, and every
|
|
53
|
+
* review read requires `thread.org_id` to equal the trace's org, so its runs
|
|
54
|
+
* never reach Human Review. The run that executed under an org is the proof of
|
|
55
|
+
* which org the thread belongs to: adopt it, for the thread's own owner only
|
|
56
|
+
* and only while `org_id` is NULL.
|
|
57
|
+
*
|
|
58
|
+
* A private thread's `org_id` grants nothing but that review access (owner
|
|
59
|
+
* access ignores it, shares do not read it, and `visibility = 'org'` is the only
|
|
60
|
+
* way it scopes sharing), while `thread_data` holds every run's conversation. So
|
|
61
|
+
* a private thread whose owner's runs span more than one org belongs to none of
|
|
62
|
+
* them: the second statement unassigns it. Org-visible threads keep their
|
|
63
|
+
* `org_id`, which is an explicit sharing scope.
|
|
64
|
+
*
|
|
65
|
+
* Both statements run after this run's own summary is committed
|
|
66
|
+
* (`upsertTraceSummary` is awaited first), so of two concurrent runs under
|
|
67
|
+
* different orgs the one whose statements run later always sees the other's
|
|
68
|
+
* committed org. If this run's adopt raced ahead of the other run's summary, the
|
|
69
|
+
* other run's unassign undoes it, or, when that ran before this adopt
|
|
70
|
+
* committed, this run's own unassign does, since it starts after the adopt.
|
|
71
|
+
* No lock is needed.
|
|
72
|
+
*
|
|
73
|
+
* The multi-org signal is derived from `agent_trace_summaries`, so it is only
|
|
74
|
+
* as durable as those rows: retention purges them, and a run that never wrote a
|
|
75
|
+
* summary is invisible to it. A thread unassigned for spanning orgs can
|
|
76
|
+
* therefore be re-adopted once the other org's summaries age out.
|
|
77
|
+
*/
|
|
78
|
+
export declare function adoptTraceOrgForThread(summary: Pick<TraceSummary, "threadId" | "userId" | "orgId">): Promise<void>;
|
|
51
79
|
export declare function getOrgScopedThreadData(orgId: string, ownerEmail: string, threadIds: readonly string[]): Promise<Map<string, string | null>>;
|
|
52
80
|
export declare function getOrgScopedThreadTitles(orgId: string, ownerEmail: string, threadIds: readonly string[]): Promise<Map<string, string>>;
|
|
53
81
|
export declare function getOrgScopedReviewThreads(requested: readonly (ObservabilityReviewThreadScope & {
|
|
@@ -660,6 +660,64 @@ export async function getTraceSummary(runId, opts = {}) {
|
|
|
660
660
|
return null;
|
|
661
661
|
return rowToTraceSummary(rows[0]);
|
|
662
662
|
}
|
|
663
|
+
/**
|
|
664
|
+
* A thread created on a path with no request org keeps `org_id` NULL, and every
|
|
665
|
+
* review read requires `thread.org_id` to equal the trace's org, so its runs
|
|
666
|
+
* never reach Human Review. The run that executed under an org is the proof of
|
|
667
|
+
* which org the thread belongs to: adopt it, for the thread's own owner only
|
|
668
|
+
* and only while `org_id` is NULL.
|
|
669
|
+
*
|
|
670
|
+
* A private thread's `org_id` grants nothing but that review access (owner
|
|
671
|
+
* access ignores it, shares do not read it, and `visibility = 'org'` is the only
|
|
672
|
+
* way it scopes sharing), while `thread_data` holds every run's conversation. So
|
|
673
|
+
* a private thread whose owner's runs span more than one org belongs to none of
|
|
674
|
+
* them: the second statement unassigns it. Org-visible threads keep their
|
|
675
|
+
* `org_id`, which is an explicit sharing scope.
|
|
676
|
+
*
|
|
677
|
+
* Both statements run after this run's own summary is committed
|
|
678
|
+
* (`upsertTraceSummary` is awaited first), so of two concurrent runs under
|
|
679
|
+
* different orgs the one whose statements run later always sees the other's
|
|
680
|
+
* committed org. If this run's adopt raced ahead of the other run's summary, the
|
|
681
|
+
* other run's unassign undoes it, or, when that ran before this adopt
|
|
682
|
+
* committed, this run's own unassign does, since it starts after the adopt.
|
|
683
|
+
* No lock is needed.
|
|
684
|
+
*
|
|
685
|
+
* The multi-org signal is derived from `agent_trace_summaries`, so it is only
|
|
686
|
+
* as durable as those rows: retention purges them, and a run that never wrote a
|
|
687
|
+
* summary is invisible to it. A thread unassigned for spanning orgs can
|
|
688
|
+
* therefore be re-adopted once the other org's summaries age out.
|
|
689
|
+
*/
|
|
690
|
+
export async function adoptTraceOrgForThread(summary) {
|
|
691
|
+
if (!summary.orgId || !summary.threadId || !summary.userId)
|
|
692
|
+
return;
|
|
693
|
+
const client = getDbExec();
|
|
694
|
+
// The subqueries only run for a thread owned by the caller (the other
|
|
695
|
+
// predicates short-circuit first) and probe
|
|
696
|
+
// idx_trace_summaries_thread_user_created by thread_id.
|
|
697
|
+
await client.execute({
|
|
698
|
+
sql: `UPDATE chat_threads SET org_id = ?
|
|
699
|
+
WHERE id = ? AND org_id IS NULL AND LOWER(owner_email) = LOWER(?)
|
|
700
|
+
AND NOT EXISTS (
|
|
701
|
+
SELECT 1 FROM agent_trace_summaries other
|
|
702
|
+
WHERE other.thread_id = chat_threads.id
|
|
703
|
+
AND LOWER(other.user_id) = LOWER(chat_threads.owner_email)
|
|
704
|
+
AND other.org_id IS NOT NULL AND other.org_id <> ?
|
|
705
|
+
)`,
|
|
706
|
+
args: [summary.orgId, summary.threadId, summary.userId, summary.orgId],
|
|
707
|
+
});
|
|
708
|
+
await client.execute({
|
|
709
|
+
sql: `UPDATE chat_threads SET org_id = NULL
|
|
710
|
+
WHERE id = ? AND org_id IS NOT NULL AND visibility = 'private'
|
|
711
|
+
AND LOWER(owner_email) = LOWER(?)
|
|
712
|
+
AND EXISTS (
|
|
713
|
+
SELECT 1 FROM agent_trace_summaries other
|
|
714
|
+
WHERE other.thread_id = chat_threads.id
|
|
715
|
+
AND LOWER(other.user_id) = LOWER(chat_threads.owner_email)
|
|
716
|
+
AND other.org_id IS NOT NULL AND other.org_id <> chat_threads.org_id
|
|
717
|
+
)`,
|
|
718
|
+
args: [summary.threadId, summary.userId],
|
|
719
|
+
});
|
|
720
|
+
}
|
|
663
721
|
export async function getOrgScopedThreadData(orgId, ownerEmail, threadIds) {
|
|
664
722
|
const ids = [...new Set(threadIds.filter(Boolean))];
|
|
665
723
|
if (!orgId || !ownerEmail || ids.length === 0)
|
|
@@ -6,7 +6,7 @@ import { MAX_AI_CONTENT_BYTES, MAX_AI_SPANS_PER_RUN, boundAiContent, emitAiSpanE
|
|
|
6
6
|
import { sanitizeToolErrorMessage, TOOL_ERROR_DETAIL_METADATA_KEY, toolErrorSignature, } from "./trace-error.js";
|
|
7
7
|
import { redactCapturedString, redactSensitiveFields, } from "./trace-redaction.js";
|
|
8
8
|
export { redactSensitiveFields } from "./trace-redaction.js";
|
|
9
|
-
import { recordAgentToolCall, recordGenAiChat } from "./metrics.js";
|
|
9
|
+
import { recordAgentToolCall, recordGenAiChat, recordTraceWriteFailure, } from "./metrics.js";
|
|
10
10
|
import { endAgentSpan, startAgentSpan, withAgentSpanContext, } from "./tracing.js";
|
|
11
11
|
import { trackingIdentityProperties } from "./tracking-identity.js";
|
|
12
12
|
function spanId() {
|
|
@@ -1328,7 +1328,7 @@ export async function instrumentAgentLoop(opts) {
|
|
|
1328
1328
|
model: usage?.model ?? loopOpts.model,
|
|
1329
1329
|
createdAt: runStart,
|
|
1330
1330
|
};
|
|
1331
|
-
writeTraceData(spans, summary, runId, config).catch(() =>
|
|
1331
|
+
writeTraceData(spans, summary, runId, config).catch((error) => reportTraceWriteFailure(runId, "write", error));
|
|
1332
1332
|
try {
|
|
1333
1333
|
// Metrics are unsampled and independent of trace export.
|
|
1334
1334
|
for (const [tripIndex, trip] of modelRoundTrips.entries()) {
|
|
@@ -1463,6 +1463,7 @@ export async function instrumentAgentLoop(opts) {
|
|
|
1463
1463
|
if (precedingResponse) {
|
|
1464
1464
|
const { inferAndTrackSentiment } = await import("./sentiment.js");
|
|
1465
1465
|
await inferAndTrackSentiment({
|
|
1466
|
+
runEngine: loopOpts.engine,
|
|
1466
1467
|
classifierModel: config.inferredSentimentModel,
|
|
1467
1468
|
precedingResponseModel: precedingResponse.model,
|
|
1468
1469
|
text: opts.sentimentInput,
|
|
@@ -1480,10 +1481,41 @@ export async function instrumentAgentLoop(opts) {
|
|
|
1480
1481
|
}
|
|
1481
1482
|
return usage;
|
|
1482
1483
|
}
|
|
1484
|
+
/**
|
|
1485
|
+
* A trace that fails to persist leaves the run unreviewable and makes a
|
|
1486
|
+
* thumbs-down for it unlinkable, so it is reported once per run and stage,
|
|
1487
|
+
* never silently and never per span.
|
|
1488
|
+
*/
|
|
1489
|
+
function reportTraceWriteFailure(runId, stage, error, detail = {}) {
|
|
1490
|
+
recordTraceWriteFailure(stage, error);
|
|
1491
|
+
console.warn(`[agent-native] observability: could not persist trace ${stage} for run ${runId}`, {
|
|
1492
|
+
...detail,
|
|
1493
|
+
error: toolErrorSignature(error instanceof Error ? error.message : String(error)),
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1483
1496
|
async function writeTraceData(spans, summary, runId, config) {
|
|
1484
|
-
const { insertTraceSpan, upsertTraceSummary } = await import("./store.js");
|
|
1485
|
-
|
|
1486
|
-
|
|
1497
|
+
const { adoptTraceOrgForThread, insertTraceSpan, upsertTraceSummary } = await import("./store.js");
|
|
1498
|
+
let spanFailures = 0;
|
|
1499
|
+
let firstSpanError;
|
|
1500
|
+
await Promise.all(spans.map((span) => insertTraceSpan({ ...span, orgId: summary.orgId ?? null }).catch((error) => {
|
|
1501
|
+
spanFailures += 1;
|
|
1502
|
+
firstSpanError ??= error;
|
|
1503
|
+
})));
|
|
1504
|
+
if (spanFailures > 0) {
|
|
1505
|
+
reportTraceWriteFailure(runId, "spans", firstSpanError, {
|
|
1506
|
+
failed: spanFailures,
|
|
1507
|
+
total: spans.length,
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
// Adoption reads other runs' summaries to detect a thread spanning orgs, so
|
|
1511
|
+
// it is only sound once this run's own org is on record too.
|
|
1512
|
+
const summaryWritten = await upsertTraceSummary(summary).then(() => true, (error) => {
|
|
1513
|
+
reportTraceWriteFailure(runId, "summary", error);
|
|
1514
|
+
return false;
|
|
1515
|
+
});
|
|
1516
|
+
if (summaryWritten) {
|
|
1517
|
+
await adoptTraceOrgForThread(summary).catch((error) => reportTraceWriteFailure(runId, "thread_org", error));
|
|
1518
|
+
}
|
|
1487
1519
|
try {
|
|
1488
1520
|
const { evaluateRun } = await import("./evals.js");
|
|
1489
1521
|
await evaluateRun(runId, { sampleRate: config.evalSampleRate });
|
package/dist/org/handlers.d.ts
CHANGED
|
@@ -72,9 +72,9 @@ export declare const setWorkspaceAppDefaultVisibilityHandler: import("h3").Event
|
|
|
72
72
|
}>>;
|
|
73
73
|
export declare const createOrgHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
74
74
|
success: boolean;
|
|
75
|
-
id?: undefined;
|
|
76
75
|
name?: undefined;
|
|
77
76
|
role?: undefined;
|
|
77
|
+
id?: undefined;
|
|
78
78
|
} | {
|
|
79
79
|
success?: undefined;
|
|
80
80
|
id: string;
|
package/dist/progress/actions.js
CHANGED
|
@@ -15,6 +15,7 @@ function parseLimit(value, fallback = 20) {
|
|
|
15
15
|
export function createProgressToolEntries(getCurrentUser) {
|
|
16
16
|
return {
|
|
17
17
|
"manage-progress": {
|
|
18
|
+
confirmsAutomationWork: false,
|
|
18
19
|
tool: {
|
|
19
20
|
description: `Track multi-step task progress visible to the user in the runs tray.
|
|
20
21
|
|
|
@@ -75,9 +75,8 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
|
|
|
75
75
|
user: "user";
|
|
76
76
|
}>>;
|
|
77
77
|
}, z.core.$strip>>, {
|
|
78
|
-
|
|
78
|
+
id?: undefined;
|
|
79
79
|
message?: undefined;
|
|
80
|
-
found?: undefined;
|
|
81
80
|
providers: {
|
|
82
81
|
id: string;
|
|
83
82
|
label: string;
|
|
@@ -89,45 +88,46 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
|
|
|
89
88
|
}[];
|
|
90
89
|
count: number;
|
|
91
90
|
provider?: undefined;
|
|
91
|
+
found?: undefined;
|
|
92
|
+
deleted?: undefined;
|
|
92
93
|
registered?: undefined;
|
|
93
|
-
id?: undefined;
|
|
94
94
|
label?: undefined;
|
|
95
95
|
} | {
|
|
96
|
-
|
|
96
|
+
id?: undefined;
|
|
97
|
+
count?: undefined;
|
|
97
98
|
message?: undefined;
|
|
98
99
|
providers?: undefined;
|
|
99
|
-
count?: undefined;
|
|
100
100
|
found: boolean;
|
|
101
101
|
provider: import("../custom-registry.js").CustomProviderConfig;
|
|
102
|
+
deleted?: undefined;
|
|
102
103
|
registered?: undefined;
|
|
103
|
-
id?: undefined;
|
|
104
104
|
label?: undefined;
|
|
105
105
|
} | {
|
|
106
|
-
|
|
106
|
+
count?: undefined;
|
|
107
107
|
message?: undefined;
|
|
108
108
|
providers?: undefined;
|
|
109
|
-
count?: undefined;
|
|
110
109
|
provider?: undefined;
|
|
111
110
|
found: boolean;
|
|
112
111
|
id: string;
|
|
112
|
+
deleted?: undefined;
|
|
113
113
|
registered?: undefined;
|
|
114
114
|
label?: undefined;
|
|
115
115
|
} | {
|
|
116
|
+
count?: undefined;
|
|
116
117
|
message?: undefined;
|
|
117
|
-
found?: undefined;
|
|
118
118
|
providers?: undefined;
|
|
119
|
-
count?: undefined;
|
|
120
119
|
provider?: undefined;
|
|
120
|
+
found?: undefined;
|
|
121
121
|
deleted: boolean;
|
|
122
122
|
id: string;
|
|
123
123
|
registered?: undefined;
|
|
124
124
|
label?: undefined;
|
|
125
125
|
} | {
|
|
126
|
-
deleted?: undefined;
|
|
127
|
-
found?: undefined;
|
|
128
|
-
providers?: undefined;
|
|
129
126
|
count?: undefined;
|
|
127
|
+
providers?: undefined;
|
|
130
128
|
provider?: undefined;
|
|
129
|
+
found?: undefined;
|
|
130
|
+
deleted?: undefined;
|
|
131
131
|
registered: boolean;
|
|
132
132
|
id: string;
|
|
133
133
|
label: string;
|
|
@@ -311,11 +311,10 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
|
|
|
311
311
|
notes?: string | undefined;
|
|
312
312
|
scope?: "org" | "user" | undefined;
|
|
313
313
|
}, {
|
|
314
|
-
|
|
314
|
+
message?: undefined;
|
|
315
315
|
deleted?: undefined;
|
|
316
|
+
id?: undefined;
|
|
316
317
|
provider?: undefined;
|
|
317
|
-
message?: undefined;
|
|
318
|
-
found?: undefined;
|
|
319
318
|
providers: {
|
|
320
319
|
id: string;
|
|
321
320
|
label: string;
|
|
@@ -326,34 +325,35 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
|
|
|
326
325
|
updatedAt: number;
|
|
327
326
|
}[];
|
|
328
327
|
count: number;
|
|
328
|
+
found?: undefined;
|
|
329
329
|
registered?: undefined;
|
|
330
330
|
label?: undefined;
|
|
331
331
|
} | {
|
|
332
|
-
id?: undefined;
|
|
333
|
-
deleted?: undefined;
|
|
334
332
|
message?: undefined;
|
|
335
|
-
|
|
333
|
+
deleted?: undefined;
|
|
334
|
+
id?: undefined;
|
|
336
335
|
count?: undefined;
|
|
336
|
+
providers?: undefined;
|
|
337
337
|
found: boolean;
|
|
338
338
|
provider: import("../custom-registry.js").CustomProviderConfig;
|
|
339
339
|
registered?: undefined;
|
|
340
340
|
label?: undefined;
|
|
341
341
|
} | {
|
|
342
|
+
message?: undefined;
|
|
342
343
|
deleted?: undefined;
|
|
343
344
|
provider?: undefined;
|
|
344
|
-
message?: undefined;
|
|
345
|
-
providers?: undefined;
|
|
346
345
|
count?: undefined;
|
|
346
|
+
providers?: undefined;
|
|
347
347
|
found: boolean;
|
|
348
348
|
id: string;
|
|
349
349
|
registered?: undefined;
|
|
350
350
|
label?: undefined;
|
|
351
351
|
} | {
|
|
352
|
-
provider?: undefined;
|
|
353
352
|
message?: undefined;
|
|
354
|
-
|
|
355
|
-
providers?: undefined;
|
|
353
|
+
provider?: undefined;
|
|
356
354
|
count?: undefined;
|
|
355
|
+
providers?: undefined;
|
|
356
|
+
found?: undefined;
|
|
357
357
|
deleted: boolean;
|
|
358
358
|
id: string;
|
|
359
359
|
registered?: undefined;
|
|
@@ -361,9 +361,9 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
|
|
|
361
361
|
} | {
|
|
362
362
|
deleted?: undefined;
|
|
363
363
|
provider?: undefined;
|
|
364
|
-
found?: undefined;
|
|
365
|
-
providers?: undefined;
|
|
366
364
|
count?: undefined;
|
|
365
|
+
providers?: undefined;
|
|
366
|
+
found?: undefined;
|
|
367
367
|
registered: boolean;
|
|
368
368
|
id: string;
|
|
369
369
|
label: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { defineAction, } from "../../action.js";
|
|
3
3
|
import { getCredentialContext } from "../../server/request-context.js";
|
|
4
|
+
import { rejectFailedProviderResult } from "../result-outcome.js";
|
|
4
5
|
import { stagingExecuteRequest } from "../staging.js";
|
|
5
6
|
import { createCustomProviderRegistrationAction, } from "./custom-provider-registration.js";
|
|
6
7
|
import { buildProviderApiAuditSummary } from "./provider-api-audit.js";
|
|
@@ -261,7 +262,7 @@ export function createProviderApiRequestAction(runtime, options = {}) {
|
|
|
261
262
|
rethrowStagingError(error);
|
|
262
263
|
}
|
|
263
264
|
}
|
|
264
|
-
return runtime.executeRequest(args);
|
|
265
|
+
return rejectFailedProviderResult(args.provider, await runtime.executeRequest(args));
|
|
265
266
|
},
|
|
266
267
|
});
|
|
267
268
|
}
|
|
@@ -291,7 +292,10 @@ export function createProviderApiDocsAction(runtime, options = {}) {
|
|
|
291
292
|
schema,
|
|
292
293
|
http: options.http ?? { method: "GET" },
|
|
293
294
|
readOnly: true,
|
|
294
|
-
run: async (rawArgs) =>
|
|
295
|
+
run: async (rawArgs) => {
|
|
296
|
+
const args = rawArgs;
|
|
297
|
+
return rejectFailedProviderResult(args.provider, await runtime.fetchDocs(args));
|
|
298
|
+
},
|
|
295
299
|
});
|
|
296
300
|
}
|
|
297
301
|
export function createProviderApiActions(runtime, options = {}) {
|
|
@@ -513,3 +513,4 @@ export declare function readGitHubRepositoryFile(args: GitHubRepositoryFileReadA
|
|
|
513
513
|
export declare function writeGitHubRepositoryFile(args: GitHubRepositoryFileWriteArgs, runtime: ProviderApiRuntimeOptions): Promise<GitHubRepositoryFileWriteResult>;
|
|
514
514
|
export declare function deleteGitHubRepositoryFile(args: GitHubRepositoryFileDeleteArgs, runtime: ProviderApiRuntimeOptions): Promise<GitHubRepositoryFileDeleteResult>;
|
|
515
515
|
export declare function defaultProviderApiCredentialResolver(options: ProviderApiCredentialLookupOptions): Promise<ProviderApiResolvedCredential | null>;
|
|
516
|
+
export declare function providerApiResponseOutcomeForUrl(url: string, response: Pick<ProviderApiHttpResponse, "ok" | "statusText">, body: string): Pick<ProviderApiHttpResponse, "ok" | "statusText">;
|
|
@@ -3950,6 +3950,24 @@ function providerQuotaExhaustedResponse(detail) {
|
|
|
3950
3950
|
},
|
|
3951
3951
|
};
|
|
3952
3952
|
}
|
|
3953
|
+
export function providerApiResponseOutcomeForUrl(url, response, body) {
|
|
3954
|
+
const target = new URL(url);
|
|
3955
|
+
const config = Object.values(PROVIDER_CONFIGS).find((candidate) => {
|
|
3956
|
+
if (!candidate.bodyOkField)
|
|
3957
|
+
return false;
|
|
3958
|
+
const base = new URL(candidate.defaultBaseUrl);
|
|
3959
|
+
const path = base.pathname.replace(/\/$/, "");
|
|
3960
|
+
return (target.origin === base.origin &&
|
|
3961
|
+
(target.pathname === path || target.pathname.startsWith(`${path}/`)));
|
|
3962
|
+
});
|
|
3963
|
+
return config
|
|
3964
|
+
? applyBodyEnvelopeOutcome({
|
|
3965
|
+
ok: response.ok,
|
|
3966
|
+
statusText: response.statusText,
|
|
3967
|
+
json: tryParseJson(body),
|
|
3968
|
+
}, config)
|
|
3969
|
+
: response;
|
|
3970
|
+
}
|
|
3953
3971
|
function applyBodyEnvelopeOutcome(response, config) {
|
|
3954
3972
|
const field = config.bodyOkField;
|
|
3955
3973
|
if (!field || !response.ok)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function rejectFailedProviderResult<T>(provider: string, result: T): T;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { fail } from "../action.js";
|
|
2
|
+
export function rejectFailedProviderResult(provider, result) {
|
|
3
|
+
if (!result || typeof result !== "object")
|
|
4
|
+
return result;
|
|
5
|
+
const record = result;
|
|
6
|
+
const response = record.response && typeof record.response === "object"
|
|
7
|
+
? record.response
|
|
8
|
+
: record;
|
|
9
|
+
if (response.ok !== false)
|
|
10
|
+
return result;
|
|
11
|
+
const status = response.status;
|
|
12
|
+
fail(`${provider}: HTTP ${status} ${response.statusText ?? ""}\n\n${JSON.stringify(response.json ?? response.text ?? response).slice(0, 2000)}`, {
|
|
13
|
+
statusCode: typeof status === "number" && status >= 400 && status <= 599
|
|
14
|
+
? status
|
|
15
|
+
: 400,
|
|
16
|
+
errorCode: typeof status === "number" && status >= 400
|
|
17
|
+
? `http_${status}`
|
|
18
|
+
: "provider_api_rejected",
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
* secret redaction are fully preserved. We read the raw (pre-redacted) JSON
|
|
24
24
|
* here; redaction is applied to the response returned to the model.
|
|
25
25
|
*/
|
|
26
|
+
import { fail } from "../action.js";
|
|
27
|
+
import { rejectFailedProviderResult } from "./result-outcome.js";
|
|
26
28
|
import { upsertStagedDataset, deriveColumns, MAX_ROWS_PER_APP, } from "./staged-datasets-store.js";
|
|
27
29
|
function getAtPath(obj, path) {
|
|
28
30
|
if (!path || obj === undefined || obj === null)
|
|
@@ -174,18 +176,21 @@ export async function stagingExecuteRequest(args, execute, ctx) {
|
|
|
174
176
|
const retryAt = typeof json?.retryAt === "string"
|
|
175
177
|
? ` Retry after ${json.retryAt}.`
|
|
176
178
|
: "";
|
|
177
|
-
|
|
179
|
+
fail(`Provider API quota exhausted (429).${retryAt}`, {
|
|
180
|
+
statusCode: 429,
|
|
181
|
+
errorCode: "http_429",
|
|
182
|
+
});
|
|
178
183
|
}
|
|
179
184
|
if (attempt >= 5) {
|
|
180
|
-
|
|
181
|
-
`Try again later or reduce the page count
|
|
185
|
+
fail(`Provider returned 429 Too Many Requests after ${attempt + 1} attempts. ` +
|
|
186
|
+
`Try again later or reduce the page count.`, { statusCode: 429, errorCode: "http_429" });
|
|
182
187
|
}
|
|
183
188
|
const waitMs = getRetryAfterMs(response.headers, attempt);
|
|
184
189
|
await sleepMs(waitMs);
|
|
185
190
|
attempt++;
|
|
186
191
|
continue;
|
|
187
192
|
}
|
|
188
|
-
result = raw;
|
|
193
|
+
result = rejectFailedProviderResult(args.provider, raw);
|
|
189
194
|
break;
|
|
190
195
|
}
|
|
191
196
|
pages++;
|
|
@@ -195,11 +200,7 @@ export async function stagingExecuteRequest(args, execute, ctx) {
|
|
|
195
200
|
}
|
|
196
201
|
const response = result.response;
|
|
197
202
|
if (!response?.ok) {
|
|
198
|
-
|
|
199
|
-
throw new Error(`Provider API returned status ${response?.status}: ${JSON.stringify(response?.json ?? response?.text).slice(0, 200)}`);
|
|
200
|
-
}
|
|
201
|
-
truncated = true;
|
|
202
|
-
break;
|
|
203
|
+
fail(`Provider API returned status ${response?.status}: ${JSON.stringify(response?.json ?? response?.text).slice(0, 200)}`, { errorCode: "provider_api_rejected" });
|
|
203
204
|
}
|
|
204
205
|
const body = response.json ??
|
|
205
206
|
(response.text ? tryParseJson(response.text) : null);
|
|
@@ -39,8 +39,8 @@ export declare function handleUpdateResource(event: any): Promise<import("./stor
|
|
|
39
39
|
error: string;
|
|
40
40
|
}>;
|
|
41
41
|
export declare function handleDeleteResource(event: any): Promise<{
|
|
42
|
-
ok?: undefined;
|
|
43
42
|
error: string;
|
|
43
|
+
ok?: undefined;
|
|
44
44
|
} | {
|
|
45
45
|
error?: undefined;
|
|
46
46
|
ok: boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ResourceMeta, type EffectiveResourceContext, type ResourceVisibility, type ResourceCreatedBy } from "./store.js";
|
|
2
2
|
type ResourceHelperScope = "personal" | "shared" | "workspace";
|
|
3
|
+
export declare function assertCanManageSharedResource(): Promise<void>;
|
|
3
4
|
export declare function readResource(path: string, options?: {
|
|
4
5
|
shared?: boolean;
|
|
5
6
|
scope?: ResourceHelperScope;
|
|
@@ -18,7 +18,7 @@ function getOwnerForScope(scope) {
|
|
|
18
18
|
function resolveScope(options) {
|
|
19
19
|
return options?.scope ?? (options?.shared ? "shared" : "personal");
|
|
20
20
|
}
|
|
21
|
-
async function assertCanManageSharedResource() {
|
|
21
|
+
export async function assertCanManageSharedResource() {
|
|
22
22
|
const orgId = getRequestOrgId();
|
|
23
23
|
if (!orgId)
|
|
24
24
|
return;
|