@superblocksteam/vite-plugin-file-sync 2.0.139-next.0 → 2.0.139-next.1
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/ai-service/agent/tools/apis/api-validation-orchestrator.js +1 -1
- package/dist/ai-service/agent/tools/apis/api-validation-orchestrator.js.map +1 -1
- package/dist/ai-service/app-interface/npm-registry.d.ts.map +1 -1
- package/dist/ai-service/app-interface/npm-registry.js +8 -22
- package/dist/ai-service/app-interface/npm-registry.js.map +1 -1
- package/dist/ai-service/app-skills/helpers.d.ts.map +1 -1
- package/dist/ai-service/app-skills/helpers.js +0 -2
- package/dist/ai-service/app-skills/helpers.js.map +1 -1
- package/dist/ai-service/index.d.ts.map +1 -1
- package/dist/ai-service/index.js +25 -107
- package/dist/ai-service/index.js.map +1 -1
- package/dist/ai-service/state-machine/clark-fsm.d.ts +1 -19
- package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -1
- package/dist/ai-service/state-machine/clark-fsm.js +0 -4
- package/dist/ai-service/state-machine/clark-fsm.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/agent-planning.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/agent-planning.js +0 -25
- package/dist/ai-service/state-machine/handlers/agent-planning.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/awaiting-user.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/awaiting-user.js +0 -21
- package/dist/ai-service/state-machine/handlers/awaiting-user.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/idle.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/idle.js +1 -16
- package/dist/ai-service/state-machine/handlers/idle.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.js +1 -10
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/transition.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/transition.js +1 -5
- package/dist/ai-service/state-machine/helpers/transition.js.map +1 -1
- package/dist/ai-service/state-machine/traced-fsm.d.ts +1 -6
- package/dist/ai-service/state-machine/traced-fsm.d.ts.map +1 -1
- package/dist/ai-service/state-machine/traced-fsm.js +3 -13
- package/dist/ai-service/state-machine/traced-fsm.js.map +1 -1
- package/dist/sync-service/index.d.ts +9 -16
- package/dist/sync-service/index.d.ts.map +1 -1
- package/dist/sync-service/index.js +4 -154
- package/dist/sync-service/index.js.map +1 -1
- package/dist/util/logger.d.ts +0 -7
- package/dist/util/logger.d.ts.map +1 -1
- package/dist/util/logger.js +0 -29
- package/dist/util/logger.js.map +1 -1
- package/package.json +8 -8
- package/dist/ai-service/state-machine/helpers/prompt-failure.d.ts +0 -51
- package/dist/ai-service/state-machine/helpers/prompt-failure.d.ts.map +0 -1
- package/dist/ai-service/state-machine/helpers/prompt-failure.js +0 -149
- package/dist/ai-service/state-machine/helpers/prompt-failure.js.map +0 -1
- package/dist/ai-service/state-machine/helpers/prompt-request-metrics.d.ts +0 -70
- package/dist/ai-service/state-machine/helpers/prompt-request-metrics.d.ts.map +0 -1
- package/dist/ai-service/state-machine/helpers/prompt-request-metrics.js +0 -201
- package/dist/ai-service/state-machine/helpers/prompt-request-metrics.js.map +0 -1
package/dist/ai-service/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { stepCountIs, streamText as aiStreamText, } from "ai";
|
|
4
|
+
import { generateObject, stepCountIs, streamText as aiStreamText, } from "ai";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { AiGenerationState, AiMode, resolveAttachmentFileName, } from "@superblocksteam/library-shared/types";
|
|
7
7
|
import { addTracingToMethods, classifyAttachmentDelivery, FactAccessType, FactCreatedSource, FactEntityScope, TracedEventEmitter, getAiQuotaPaywallReasonFromMessage, } from "@superblocksteam/shared";
|
|
@@ -72,7 +72,6 @@ import { classificationHelper } from "./state-machine/helpers/classification.js"
|
|
|
72
72
|
import { getContextId } from "./state-machine/helpers/context-id.js";
|
|
73
73
|
import { sendUserGenerationStateChannel } from "./state-machine/helpers/peer.js";
|
|
74
74
|
import { sendUserMessageChannel, clearPendingToolPermissionRequest, } from "./state-machine/helpers/peer.js";
|
|
75
|
-
import { promptFailureFromStreamAbort, promptFailurePaywall, promptFailurePlatform, promptFailureUserCanceled, recordPromptAttempt, recordPromptEntryRejection, recordPromptOutcome, recordAwaitingUserHandoffDismissed, resolvePromptOutcomeDedupeKey, resolvePromptRequestDedupeKey, } from "./state-machine/helpers/prompt-request-metrics.js";
|
|
76
75
|
import { catchBackgroundPeerDisconnect, StablePeer, } from "./state-machine/helpers/stable-peer.js";
|
|
77
76
|
import { transitionFrom } from "./state-machine/helpers/transition.js";
|
|
78
77
|
import { isTaskAccessibleTo, registerBackgroundTaskTypes, resyncActiveTaskStatusesToPeer, TaskStore, wireTaskStatusPushToPeer, } from "./tasks/index.js";
|
|
@@ -1022,16 +1021,12 @@ export class AiService extends TracedEventEmitter {
|
|
|
1022
1021
|
if (clark.context.abortController?.signal.aborted &&
|
|
1023
1022
|
event.type !== USER_CANCELED &&
|
|
1024
1023
|
event.type !== AGENT_CANCELED) {
|
|
1025
|
-
return clark.send({
|
|
1026
|
-
type: USER_CANCELED,
|
|
1027
|
-
failure: promptFailureFromStreamAbort(clark.context),
|
|
1028
|
-
});
|
|
1024
|
+
return clark.send({ type: USER_CANCELED });
|
|
1029
1025
|
}
|
|
1030
1026
|
if (event.type !== AGENT_CANCELED) {
|
|
1031
1027
|
return clark.send({
|
|
1032
1028
|
type: AGENT_CANCELED,
|
|
1033
1029
|
advice: `An unexpected error occurred. Please try again.`,
|
|
1034
|
-
failure: promptFailurePlatform("handler_error"),
|
|
1035
1030
|
});
|
|
1036
1031
|
}
|
|
1037
1032
|
throw error;
|
|
@@ -1389,14 +1384,14 @@ export class AiService extends TracedEventEmitter {
|
|
|
1389
1384
|
async tryHandlePaywallForRequest(request) {
|
|
1390
1385
|
try {
|
|
1391
1386
|
await this.ensureAiQuotaAvailable(request.jwt);
|
|
1392
|
-
return
|
|
1387
|
+
return false;
|
|
1393
1388
|
}
|
|
1394
1389
|
catch (error) {
|
|
1395
1390
|
if (error instanceof Error) {
|
|
1396
1391
|
const reason = getAiQuotaPaywallReasonFromMessage(error.message);
|
|
1397
1392
|
if (reason) {
|
|
1398
1393
|
await this.handlePreCallPaywall(request, reason);
|
|
1399
|
-
return
|
|
1394
|
+
return true;
|
|
1400
1395
|
}
|
|
1401
1396
|
}
|
|
1402
1397
|
throw error;
|
|
@@ -1671,10 +1666,6 @@ export class AiService extends TracedEventEmitter {
|
|
|
1671
1666
|
async handleAiGenerate(request) {
|
|
1672
1667
|
this.getLogger().info(`[ai-service] handleAiGenerate: peerId=${this.stablePeer.peerId ?? "unknown"}`);
|
|
1673
1668
|
if (this.clark.state === ClarkStateNames.Dead) {
|
|
1674
|
-
recordPromptEntryRejection({
|
|
1675
|
-
dedupeKey: resolvePromptRequestDedupeKey(request),
|
|
1676
|
-
failure: promptFailurePlatform("service_dead"),
|
|
1677
|
-
});
|
|
1678
1669
|
throw new Error("Service is unavailable");
|
|
1679
1670
|
}
|
|
1680
1671
|
// a reconnect can cause the client to re-send this prompt
|
|
@@ -1685,10 +1676,6 @@ export class AiService extends TracedEventEmitter {
|
|
|
1685
1676
|
this.assertNoActivePolicyGateRun();
|
|
1686
1677
|
if (this.isBusy()) {
|
|
1687
1678
|
this.getLogger().warn("[ai-service] Service is busy. State:", this.clark.state);
|
|
1688
|
-
recordPromptEntryRejection({
|
|
1689
|
-
dedupeKey: resolvePromptRequestDedupeKey(request),
|
|
1690
|
-
failure: promptFailurePlatform("service_busy"),
|
|
1691
|
-
});
|
|
1692
1679
|
throw new Error("Service is busy");
|
|
1693
1680
|
}
|
|
1694
1681
|
// Pre-call quota check. When denied, `ensureAiQuotaAvailable` throws so
|
|
@@ -1701,12 +1688,7 @@ export class AiService extends TracedEventEmitter {
|
|
|
1701
1688
|
// advice + open modal via the same `aiSetGenerationState(CANCELLED,
|
|
1702
1689
|
// paywallReason)` saga path the mid-stream paywall uses, then resolve
|
|
1703
1690
|
// the socket call so the UI's catch doesn't run. (APPS-4080)
|
|
1704
|
-
|
|
1705
|
-
if (paywallReason) {
|
|
1706
|
-
recordPromptEntryRejection({
|
|
1707
|
-
dedupeKey: resolvePromptRequestDedupeKey(request),
|
|
1708
|
-
failure: promptFailurePaywall(paywallReason),
|
|
1709
|
-
});
|
|
1691
|
+
if (await this.tryHandlePaywallForRequest(request)) {
|
|
1710
1692
|
return;
|
|
1711
1693
|
}
|
|
1712
1694
|
if (request.requestId &&
|
|
@@ -1714,7 +1696,6 @@ export class AiService extends TracedEventEmitter {
|
|
|
1714
1696
|
this.getLogger().warn("[ai-service] Ignoring duplicate aiGenerate re-send (lost dedup race)", { requestId: request.requestId });
|
|
1715
1697
|
return;
|
|
1716
1698
|
}
|
|
1717
|
-
recordPromptAttempt(resolvePromptRequestDedupeKey(request));
|
|
1718
1699
|
// The id is now recorded. If anything below throws before generation is
|
|
1719
1700
|
// actually kicked off (the `transitionTo` USER_SENT_PROMPT), evict it so a
|
|
1720
1701
|
// legitimate reconnect re-send of this same prompt is not swallowed as a
|
|
@@ -1731,20 +1712,14 @@ export class AiService extends TracedEventEmitter {
|
|
|
1731
1712
|
});
|
|
1732
1713
|
// Generate prompt_id for this user interaction
|
|
1733
1714
|
const promptId = randomUUID();
|
|
1734
|
-
const promptOutcomeDedupeKey = resolvePromptRequestDedupeKey(request);
|
|
1735
1715
|
getLogger().info("[ai-service] Generated prompt_id for user interaction", {
|
|
1736
1716
|
promptId,
|
|
1737
|
-
requestId: request.requestId,
|
|
1738
|
-
dedupeKeySource: request.requestId ? "requestId" : "ephemeral",
|
|
1739
1717
|
applicationId: this.config.applicationId,
|
|
1740
1718
|
});
|
|
1741
1719
|
this.clark.updateContext((context) => {
|
|
1742
1720
|
return {
|
|
1743
1721
|
...context,
|
|
1744
1722
|
promptId,
|
|
1745
|
-
promptOutcomeDedupeKey,
|
|
1746
|
-
isInterruptAbort: undefined,
|
|
1747
|
-
userInitiatedPromptAbort: undefined,
|
|
1748
1723
|
// Third-party import turns are billed as app_migration; everything
|
|
1749
1724
|
// else falls back to the default in-app Clark generation metadata.
|
|
1750
1725
|
usageMetadata: request.importSource
|
|
@@ -1779,11 +1754,6 @@ export class AiService extends TracedEventEmitter {
|
|
|
1779
1754
|
if (request.requestId) {
|
|
1780
1755
|
this.requestDeduplicator.forget(request.requestId);
|
|
1781
1756
|
}
|
|
1782
|
-
recordPromptOutcome({
|
|
1783
|
-
dedupeKey: resolvePromptRequestDedupeKey(request),
|
|
1784
|
-
outcome: "failure",
|
|
1785
|
-
failure: promptFailurePlatform("handler_error"),
|
|
1786
|
-
});
|
|
1787
1757
|
throw error;
|
|
1788
1758
|
}
|
|
1789
1759
|
}
|
|
@@ -2079,7 +2049,7 @@ export class AiService extends TracedEventEmitter {
|
|
|
2079
2049
|
application_id: this.config.applicationId,
|
|
2080
2050
|
session_id: this.sessionId,
|
|
2081
2051
|
}));
|
|
2082
|
-
const { model
|
|
2052
|
+
const { model } = llmProvider.modelForTask("fast");
|
|
2083
2053
|
const LabelAttachmentSchema = z.object({
|
|
2084
2054
|
label: z
|
|
2085
2055
|
.string()
|
|
@@ -2095,31 +2065,21 @@ export class AiService extends TracedEventEmitter {
|
|
|
2095
2065
|
try {
|
|
2096
2066
|
// Build the appropriate content part based on attachment type
|
|
2097
2067
|
const contentPart = this.attachmentToContentPart(attachment);
|
|
2098
|
-
|
|
2099
|
-
// one-shot, mirroring the APPS-1213 (#20263) migrations. No safety config:
|
|
2100
|
-
// labeling had no safety pass before this migration, and redacting the
|
|
2101
|
-
// upload before the model would defeat labeling (the model must see it).
|
|
2102
|
-
// Upload content can still carry secrets, so we keep it out of telemetry
|
|
2103
|
-
// via recordObsContent: false rather than via a safety pass.
|
|
2104
|
-
const result = await this.llmClient.generateObject({
|
|
2068
|
+
const { object: result } = await generateObject({
|
|
2105
2069
|
model,
|
|
2106
2070
|
schema: LabelAttachmentSchema,
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
],
|
|
2120
|
-
},
|
|
2121
|
-
providerConfig,
|
|
2122
|
-
retry: { maxAttempts: 2 },
|
|
2071
|
+
messages: [
|
|
2072
|
+
{
|
|
2073
|
+
role: "user",
|
|
2074
|
+
content: [
|
|
2075
|
+
{
|
|
2076
|
+
type: "text",
|
|
2077
|
+
text: "Analyze this attachment and provide a brief label and key insight about its content.",
|
|
2078
|
+
},
|
|
2079
|
+
contentPart,
|
|
2080
|
+
],
|
|
2081
|
+
},
|
|
2082
|
+
],
|
|
2123
2083
|
abortSignal: timeoutController.signal,
|
|
2124
2084
|
});
|
|
2125
2085
|
const durationMs = Date.now() - startTime;
|
|
@@ -2247,44 +2207,17 @@ export class AiService extends TracedEventEmitter {
|
|
|
2247
2207
|
await this.clark.recordSystemMessage(params, "Environment event", "User closed the integration setup form. The integration setup might not have been completed successfully.");
|
|
2248
2208
|
}
|
|
2249
2209
|
async handleUserCanceled() {
|
|
2250
|
-
|
|
2251
|
-
if (!this.isBusy() && !awaitingUser) {
|
|
2210
|
+
if (!this.isBusy()) {
|
|
2252
2211
|
return;
|
|
2253
2212
|
}
|
|
2254
|
-
this.clark.updateContext((context) => ({
|
|
2255
|
-
...context,
|
|
2256
|
-
userInitiatedPromptAbort: true,
|
|
2257
|
-
}));
|
|
2258
2213
|
this.clark.context.abortController?.abort();
|
|
2259
|
-
if (this.isBusy()) {
|
|
2260
|
-
recordPromptOutcome({
|
|
2261
|
-
dedupeKey: resolvePromptOutcomeDedupeKey(this.clark.context),
|
|
2262
|
-
outcome: "failure",
|
|
2263
|
-
failure: promptFailureUserCanceled(),
|
|
2264
|
-
});
|
|
2265
|
-
}
|
|
2266
|
-
if (awaitingUser && this.clark.context.awaitingUserHandoffRecorded) {
|
|
2267
|
-
recordAwaitingUserHandoffDismissed({
|
|
2268
|
-
awaitingUserHandoffPromptId: this.clark.context.awaitingUserHandoffPromptId,
|
|
2269
|
-
awaitingUserHandoffRecorded: this.clark.context.awaitingUserHandoffRecorded,
|
|
2270
|
-
promptId: this.clark.context.promptId,
|
|
2271
|
-
promptOutcomeDedupeKey: this.clark.context.promptOutcomeDedupeKey,
|
|
2272
|
-
reason: "cancel",
|
|
2273
|
-
});
|
|
2274
|
-
}
|
|
2275
2214
|
// Clear the prompt_id since this prompt was abandoned
|
|
2276
2215
|
this.clark.updateContext((context) => ({
|
|
2277
2216
|
...context,
|
|
2278
2217
|
promptId: undefined,
|
|
2279
|
-
promptOutcomeDedupeKey: undefined,
|
|
2280
2218
|
usageMetadata: undefined,
|
|
2281
|
-
awaitingUserHandoffPromptId: undefined,
|
|
2282
|
-
awaitingUserHandoffRecorded: undefined,
|
|
2283
2219
|
}));
|
|
2284
|
-
void this.clark.send({
|
|
2285
|
-
type: USER_CANCELED,
|
|
2286
|
-
failure: promptFailureUserCanceled(),
|
|
2287
|
-
});
|
|
2220
|
+
void this.clark.send({ type: USER_CANCELED });
|
|
2288
2221
|
}
|
|
2289
2222
|
/**
|
|
2290
2223
|
* UI-initiated cancellation of a background task. Delegates to
|
|
@@ -2335,16 +2268,11 @@ export class AiService extends TracedEventEmitter {
|
|
|
2335
2268
|
async handleAiGenerateWithQueue(request, mode) {
|
|
2336
2269
|
this.getLogger().info(`[ai-service] handleAiGenerateWithQueue: peerId=${this.stablePeer.peerId ?? "unknown"}, mode=${mode}`);
|
|
2337
2270
|
if (this.clark.state === ClarkStateNames.Dead) {
|
|
2338
|
-
recordPromptEntryRejection({
|
|
2339
|
-
dedupeKey: resolvePromptRequestDedupeKey(request),
|
|
2340
|
-
failure: promptFailurePlatform("service_dead"),
|
|
2341
|
-
});
|
|
2342
2271
|
throw new Error("Service is unavailable");
|
|
2343
2272
|
}
|
|
2344
2273
|
// peek (do not record) so a re-sent prompt is dropped before the
|
|
2345
|
-
// interrupt path tears down the in-flight generation.
|
|
2346
|
-
//
|
|
2347
|
-
// interruptAndContinue once this proceeds.
|
|
2274
|
+
// interrupt path tears down the in-flight generation. `handleAiGenerate` is
|
|
2275
|
+
// the single recording point and stamps the id once this proceeds.
|
|
2348
2276
|
if (request.requestId && this.requestDeduplicator.has(request.requestId)) {
|
|
2349
2277
|
this.getLogger().info("[ai-service] Ignoring duplicate aiGenerateWithQueue re-send", { requestId: request.requestId, mode });
|
|
2350
2278
|
return { status: "started" };
|
|
@@ -2378,10 +2306,7 @@ export class AiService extends TracedEventEmitter {
|
|
|
2378
2306
|
availableIntegrations: this.clark.context.availableIntegrations,
|
|
2379
2307
|
};
|
|
2380
2308
|
this.getLogger().info(`[ai-service] Interrupting current generation. Partial response length: ${partialResponse.length}`);
|
|
2381
|
-
this.clark.updateContext({
|
|
2382
|
-
isInterruptAbort: true,
|
|
2383
|
-
userInitiatedPromptAbort: true,
|
|
2384
|
-
});
|
|
2309
|
+
this.clark.updateContext({ isInterruptAbort: true });
|
|
2385
2310
|
this.clark.context.abortController?.abort();
|
|
2386
2311
|
await this.waitForAbortComplete();
|
|
2387
2312
|
// Note: `interruptedPreviousGeneration` and `interruptOriginalPrompt`
|
|
@@ -2397,8 +2322,6 @@ export class AiService extends TracedEventEmitter {
|
|
|
2397
2322
|
availableIntegrations: preservedContext.availableIntegrations,
|
|
2398
2323
|
abortController: new AbortController(),
|
|
2399
2324
|
partialResponse: undefined,
|
|
2400
|
-
isInterruptAbort: undefined,
|
|
2401
|
-
userInitiatedPromptAbort: undefined,
|
|
2402
2325
|
});
|
|
2403
2326
|
if (partialResponse.trim().length > 10) {
|
|
2404
2327
|
await this.chatSessionStore.recordAssistant({
|
|
@@ -2412,12 +2335,7 @@ export class AiService extends TracedEventEmitter {
|
|
|
2412
2335
|
// `handleAiGenerate`. The aborted run is NOT resumed; the user can
|
|
2413
2336
|
// start fresh once credits are restored via the same "send any
|
|
2414
2337
|
// message" affordance the standard paywall uses.
|
|
2415
|
-
|
|
2416
|
-
if (paywallReason) {
|
|
2417
|
-
recordPromptEntryRejection({
|
|
2418
|
-
dedupeKey: resolvePromptRequestDedupeKey(request),
|
|
2419
|
-
failure: promptFailurePaywall(paywallReason),
|
|
2420
|
-
});
|
|
2338
|
+
if (await this.tryHandlePaywallForRequest(request)) {
|
|
2421
2339
|
return;
|
|
2422
2340
|
}
|
|
2423
2341
|
// Only set the interrupt-state fields once we're committed to calling
|