@opengeni/worker-bundle 2.0.3 → 2.1.0-canary.36239117573001
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/activities/agent-turn/agent-build.d.ts +2 -0
- package/dist/activities/agent-turn/code-search.d.ts +60 -0
- package/dist/activities/agent-turn/codex-capacity.d.ts +13 -0
- package/dist/activities/agent-turn/errors.d.ts +12 -1
- package/dist/activities/agent-turn/governance-model.d.ts +2 -0
- package/dist/activities/agent-turn/session-title.d.ts +32 -2
- package/dist/activities/agent-turn/tool-environment.d.ts +4 -0
- package/dist/activities/context-compaction.d.ts +10 -2
- package/dist/activities/knowledge-indexing.d.ts +19 -0
- package/dist/{activities-control-IVTL723D.js → activities-control-I72CRMAE.js} +81 -14
- package/dist/activities-control-I72CRMAE.js.map +1 -0
- package/dist/{activities-turn-EZEDZTEZ.js → activities-turn-CSDKK4N3.js} +425 -46
- package/dist/activities-turn-CSDKK4N3.js.map +1 -0
- package/dist/artifact-outbox-entry.js +3 -0
- package/dist/artifact-outbox-entry.js.map +1 -1
- package/dist/{chunk-JMO5ZUW3.js → chunk-7M6G2SCF.js} +159 -11
- package/dist/chunk-7M6G2SCF.js.map +1 -0
- package/dist/{chunk-I7HKKMUJ.js → chunk-DSPP6CZL.js} +48 -3
- package/dist/chunk-DSPP6CZL.js.map +1 -0
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/observability-metrics.d.ts +11 -1
- package/dist/sandbox-resume.d.ts +46 -0
- package/dist/workflow-bundle.js +77 -2
- package/dist/workflows/session.d.ts +30 -0
- package/package.json +20 -19
- package/src/activities/agent-turn/agent-build.ts +4 -0
- package/src/activities/agent-turn/code-search.ts +275 -0
- package/src/activities/agent-turn/codex-capacity.ts +37 -2
- package/src/activities/agent-turn/compaction-prep.ts +52 -16
- package/src/activities/agent-turn/errors.ts +59 -1
- package/src/activities/agent-turn/governance-model.ts +17 -1
- package/src/activities/agent-turn/run.ts +4 -0
- package/src/activities/agent-turn/sandbox-establish.ts +12 -1
- package/src/activities/agent-turn/session-title.ts +73 -3
- package/src/activities/agent-turn/stream-attempt.ts +14 -13
- package/src/activities/agent-turn/tool-environment.ts +65 -0
- package/src/activities/context-compaction.ts +49 -14
- package/src/activities/knowledge-indexing.ts +107 -9
- package/src/activities/scheduled-tasks.ts +18 -2
- package/src/activity-services.ts +16 -4
- package/src/editable-artifact-hint-broker.ts +3 -0
- package/src/index.ts +2 -2
- package/src/observability-metrics.ts +70 -1
- package/src/personal-github-git-credentials.ts +2 -0
- package/src/sandbox-resume.ts +205 -5
- package/src/workflows/session.ts +102 -6
- package/dist/activities-control-IVTL723D.js.map +0 -1
- package/dist/activities-turn-EZEDZTEZ.js.map +0 -1
- package/dist/chunk-I7HKKMUJ.js.map +0 -1
- package/dist/chunk-JMO5ZUW3.js.map +0 -1
|
@@ -63,6 +63,8 @@ export type BuildTurnAgentDeps = {
|
|
|
63
63
|
connectorActionPolicy: ConnectorActionPolicyHooks;
|
|
64
64
|
trigger: ClaimTurnOk["trigger"];
|
|
65
65
|
preparationIndependentToolNames: readonly string[];
|
|
66
|
+
/** The attempt's tool catalog includes the Jev-backed code_search tool. */
|
|
67
|
+
codeSearchAvailable: boolean;
|
|
66
68
|
videoGenerationAcceptancesByCallId: Map<string, {
|
|
67
69
|
operationId: string;
|
|
68
70
|
requestDigest: string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { AttemptToolDefinition } from "@opengeni/codemode";
|
|
2
|
+
import { type Settings } from "@opengeni/config";
|
|
3
|
+
import { JevCircuitBreaker, type CodeSearchWorkspace } from "@opengeni/jev";
|
|
4
|
+
import type { Observability } from "@opengeni/observability";
|
|
5
|
+
import { type SandboxChannelAService } from "@opengeni/runtime/sandbox";
|
|
6
|
+
/**
|
|
7
|
+
* One breaker per worker process. Repeated Jev outages (including an exhausted
|
|
8
|
+
* account) make `code_search` calls on this worker fail at once for a cooldown
|
|
9
|
+
* instead of each running a full retry cycle. The breaker never changes which
|
|
10
|
+
* tools a turn is offered: the tool list and instructions are the start of the
|
|
11
|
+
* model's cached prompt, and sessions move between workers whose breakers
|
|
12
|
+
* disagree.
|
|
13
|
+
*/
|
|
14
|
+
export declare const codeSearchCircuitBreaker: JevCircuitBreaker;
|
|
15
|
+
type CodeSearchChannel = Pick<SandboxChannelAService, "codeSearchRipgrep" | "codeSearchPathKinds" | "fsRead">;
|
|
16
|
+
/** Adapt the turn's sandbox or Connected Machine to the code search engine. */
|
|
17
|
+
export declare function codeSearchWorkspaceFromChannel(channel: CodeSearchChannel): CodeSearchWorkspace;
|
|
18
|
+
/** Jev work done by one completed `code_search` call, for per-workspace usage records. */
|
|
19
|
+
export type CodeSearchUsage = {
|
|
20
|
+
operationId: string;
|
|
21
|
+
jevRequests: number;
|
|
22
|
+
jevInputTokens: number;
|
|
23
|
+
jevCostUsd: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The model-facing `code_search` tool. Jev scores candidates inside the worker;
|
|
27
|
+
* the sandbox only runs read-only ripgrep and file reads, so the Jev key never
|
|
28
|
+
* leaves this process. A Jev failure is reported to the model instead of
|
|
29
|
+
* degrading to keyword-only ranking, which lowered answer quality in testing.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createCodeSearchAttemptToolDefinition(input: {
|
|
32
|
+
settings: Pick<Settings, "jevApiKey" | "jevBaseUrl" | "jevModel" | "jevRequestTimeoutMs">;
|
|
33
|
+
apiKey: string;
|
|
34
|
+
workspace: () => Promise<CodeSearchWorkspace>;
|
|
35
|
+
observability: Observability;
|
|
36
|
+
/** Records Jev usage against the workspace. Failures are logged, never surfaced. */
|
|
37
|
+
recordUsage?: (usage: CodeSearchUsage) => Promise<void>;
|
|
38
|
+
breaker?: JevCircuitBreaker;
|
|
39
|
+
fetch?: typeof fetch;
|
|
40
|
+
}): AttemptToolDefinition;
|
|
41
|
+
/**
|
|
42
|
+
* The `code_search` definition for one turn, or none. It is offered only when
|
|
43
|
+
* the session's frozen decision and the deployment enable it, a usable Jev key
|
|
44
|
+
* exists, and the turn has compute that can run its POSIX shell commands (not
|
|
45
|
+
* a Windows Connected Machine). Every input is durable, so the tool list stays
|
|
46
|
+
* the same from turn to turn and on every worker. Transient Jev health never
|
|
47
|
+
* hides the tool; the breaker only refuses calls.
|
|
48
|
+
*/
|
|
49
|
+
export declare function codeSearchToolDefinitions(input: {
|
|
50
|
+
enabled: boolean;
|
|
51
|
+
settings: Pick<Settings, "jevApiKey" | "jevBaseUrl" | "jevModel" | "jevRequestTimeoutMs">;
|
|
52
|
+
backend: Settings["sandboxBackend"];
|
|
53
|
+
/** The turn's Connected Machine workspace root, when a machine is primary. */
|
|
54
|
+
machineWorkspaceRoot?: string | null;
|
|
55
|
+
observability: Observability;
|
|
56
|
+
workspace: () => Promise<CodeSearchWorkspace>;
|
|
57
|
+
recordUsage?: (usage: CodeSearchUsage) => Promise<void>;
|
|
58
|
+
breaker?: JevCircuitBreaker;
|
|
59
|
+
}): AttemptToolDefinition[];
|
|
60
|
+
export {};
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { type Settings } from "@opengeni/config";
|
|
2
2
|
import type { TurnActivityServices as ActivityServices, RunAgentTurnInput, RunAgentTurnResult } from "../types.js";
|
|
3
3
|
import { createTurnCredentialLeases } from "./credential-leases.js";
|
|
4
|
+
import { type LogThrottle } from "@opengeni/observability";
|
|
4
5
|
import type { ClaimTurnOk } from "./claim.js";
|
|
5
6
|
import type { AttemptIdentityState, BillingState, ClaimedResult, EventingState, ProviderTurnState, TurnControlState } from "./turn-context.js";
|
|
7
|
+
/** The eligible-pool gauge and `opengeni_codex_pool_low_total` stay per turn;
|
|
8
|
+
* the warning line is the first observation per workspace pool depth, then at
|
|
9
|
+
* most one per interval with the count it hid. The public log projection drops
|
|
10
|
+
* the identifiers and counts, so the closed `reason` keeps the depth visible. */
|
|
11
|
+
export declare const CODEX_POOL_LOW_WARNING_INTERVAL_MS: number;
|
|
12
|
+
export declare function warnCodexPoolLow(observability: Pick<ActivityServices["observability"], "warn">, input: {
|
|
13
|
+
workspaceKey: string;
|
|
14
|
+
workspaceId: string;
|
|
15
|
+
eligibleCount: number;
|
|
16
|
+
connectedCount: number;
|
|
17
|
+
depth: "zero" | "one";
|
|
18
|
+
}, throttle?: LogThrottle): void;
|
|
6
19
|
export type CapacityPhaseDeps = {
|
|
7
20
|
input: RunAgentTurnInput;
|
|
8
21
|
settings: Settings;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CompactionProviderRejection, type MaterializationVerificationDiagnostic } from "@opengeni/runtime";
|
|
1
|
+
import { type CompactionProviderRejection, type MaterializationVerificationDiagnostic, type ProviderQuotaExhaustion, type ProviderQuotaScope } from "@opengeni/runtime";
|
|
2
2
|
import { type McpTransportRequestFailureDiagnostic } from "@opengeni/runtime/mcp-network";
|
|
3
3
|
import { ApplicationFailure } from "@temporalio/activity";
|
|
4
4
|
import type { CodexAccountStatus } from "@opengeni/db";
|
|
@@ -168,6 +168,7 @@ export declare function compactionFailureTurnEventPayload(error: unknown, overri
|
|
|
168
168
|
recovery: "user_message";
|
|
169
169
|
compacted: false;
|
|
170
170
|
providerRejection?: CompactionProviderRejection;
|
|
171
|
+
quotaScope?: ProviderQuotaScope;
|
|
171
172
|
};
|
|
172
173
|
export declare function isCompactionSummaryFailure(error: unknown): boolean;
|
|
173
174
|
export declare function shouldRecoverCompactionProviderFailure(error: unknown): boolean;
|
|
@@ -235,6 +236,15 @@ export declare function collectErrorStrings(value: unknown, seen?: WeakSet<objec
|
|
|
235
236
|
export declare const STATUSLESS_UPSTREAM_CONNECTIVITY_MESSAGE = "unable to connect. is the computer able to access the url?";
|
|
236
237
|
export declare function isExactStatuslessUpstreamConnectivityMessage(message: string): boolean;
|
|
237
238
|
export declare function isTransientProviderError(error: unknown): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* Recognize an exhausted API-key provider quota (a daily or monthly allowance,
|
|
241
|
+
* a free-tier day cap, or an account out of credits) as distinct from an
|
|
242
|
+
* ordinary per-minute rate limit. Retrying within the bounded same-turn budget
|
|
243
|
+
* cannot succeed, so the turn fails promptly instead. Subscription transports
|
|
244
|
+
* own their quota semantics through credential rotation and durable capacity
|
|
245
|
+
* waits, so a Codex or SuperGrok transport error never classifies here.
|
|
246
|
+
*/
|
|
247
|
+
export declare function classifyProviderQuotaExhaustionError(error: unknown): ProviderQuotaExhaustion | null;
|
|
238
248
|
export type XaiCredentialFailure = {
|
|
239
249
|
kind: "auth" | "forbidden" | "rate_limit";
|
|
240
250
|
cooldownMs: number | null;
|
|
@@ -271,6 +281,7 @@ declare function baseAgentRunFailurePayload(error: unknown, options?: {
|
|
|
271
281
|
historyPersistenceStage?: MandatoryHistoryPersistenceStage;
|
|
272
282
|
mcpTransportDiagnostic?: McpTransportRequestFailureDiagnostic;
|
|
273
283
|
materializationDiagnostic?: MaterializationVerificationDiagnostic;
|
|
284
|
+
quotaScope?: ProviderQuotaScope;
|
|
274
285
|
};
|
|
275
286
|
export type CodexCredentialFailure = {
|
|
276
287
|
kind: "auth" | "forbidden" | "rate_limit" | "quota";
|
|
@@ -37,6 +37,8 @@ export type GovernanceModelOk = {
|
|
|
37
37
|
rigVersion: NonNullable<Awaited<ReturnType<typeof materializeRigVersionForAttempt>>>["version"] | null;
|
|
38
38
|
rigName: string | null;
|
|
39
39
|
agentHumanInputEnabled: boolean;
|
|
40
|
+
/** Deployment and workspace allow the Jev-backed code_search tool. */
|
|
41
|
+
codeSearchEnabled: boolean;
|
|
40
42
|
workspaceAgentInstructions: string | null | undefined;
|
|
41
43
|
workspaceGovernance: ReturnType<typeof renderWorkspaceGovernanceContext>;
|
|
42
44
|
structuredWorkspacePolicyActive: boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AttemptToolDefinition } from "@opengeni/codemode";
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
2
|
+
import { type ModelCapabilitiesV1 } from "@opengeni/config";
|
|
3
|
+
import type { GeneratedSessionTitle, GenerateSessionTitleOptions, OpenGeniRuntime } from "@opengeni/runtime";
|
|
4
|
+
import { ReasoningEffort, type FirstPartyMcpToolName, type Permission, type ToolRef } from "@opengeni/contracts";
|
|
4
5
|
export declare const SESSION_TITLE_MODEL_TOOL_NAME = "opengeni__set_session_title";
|
|
5
6
|
export declare function shouldRequestMissingSessionTitle(input: {
|
|
6
7
|
title: string | null;
|
|
@@ -8,11 +9,21 @@ export declare function shouldRequestMissingSessionTitle(input: {
|
|
|
8
9
|
firstPartyMcpTools: readonly FirstPartyMcpToolName[];
|
|
9
10
|
firstPartyMcpPermissions: readonly Permission[] | null;
|
|
10
11
|
}): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the turn's route can afford a model request spent only on a title.
|
|
14
|
+
* The managed OpenRouter free route draws on one deployment-wide per-minute
|
|
15
|
+
* and per-day request quota that users' turns need, so an untitled session on
|
|
16
|
+
* it gets no title sidecar and no title tool (whose call would cost a
|
|
17
|
+
* follow-up request). Clients keep showing the prompt preview, and a later
|
|
18
|
+
* turn on another route titles the session.
|
|
19
|
+
*/
|
|
20
|
+
export declare function routeAllowsSessionTitleRequests(resolvedModel: ReturnType<OpenGeniRuntime["resolveTurnModel"]>): boolean;
|
|
11
21
|
export declare function sessionTitleToolPlan(input: {
|
|
12
22
|
tools: readonly ToolRef[];
|
|
13
23
|
selectedFirstPartyMcpTools: readonly FirstPartyMcpToolName[];
|
|
14
24
|
shouldRequestTitle: boolean;
|
|
15
25
|
parallelGenerationAvailable: boolean;
|
|
26
|
+
routeAllowsTitleRequests: boolean;
|
|
16
27
|
}): {
|
|
17
28
|
promoteTitleTool: boolean;
|
|
18
29
|
generateTitleInParallel: boolean;
|
|
@@ -20,6 +31,25 @@ export declare function sessionTitleToolPlan(input: {
|
|
|
20
31
|
preparationIndependentToolNames: string[];
|
|
21
32
|
};
|
|
22
33
|
export declare const PARALLEL_SESSION_TITLE_TIMEOUT_MS = 15000;
|
|
34
|
+
/**
|
|
35
|
+
* The lowest reasoning effort the resolved model can run, for the auxiliary
|
|
36
|
+
* title request only. A title needs no deliberation, and a provider default
|
|
37
|
+
* effort can use most of the output budget before any visible text. Returns
|
|
38
|
+
* undefined when the model declares no runnable reasoning control, so the
|
|
39
|
+
* request carries no reasoning parameter.
|
|
40
|
+
*/
|
|
41
|
+
export declare function sessionTitleReasoningEffort(capabilities: Pick<ModelCapabilitiesV1, "reasoning"> | undefined): ReasoningEffort | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Options for the parallel title request. It uses the turn's resolved
|
|
44
|
+
* provider and credential authority, but its own lowest runnable reasoning
|
|
45
|
+
* effort rather than the turn's effort.
|
|
46
|
+
*/
|
|
47
|
+
export declare function sessionTitleGenerationOptions(input: {
|
|
48
|
+
resolvedModel: ReturnType<OpenGeniRuntime["resolveTurnModel"]>;
|
|
49
|
+
modelName: string;
|
|
50
|
+
serviceTier: GenerateSessionTitleOptions["serviceTier"] | null | undefined;
|
|
51
|
+
signal: AbortSignal;
|
|
52
|
+
}): GenerateSessionTitleOptions;
|
|
23
53
|
export type ParallelSessionTitleGeneration = {
|
|
24
54
|
finish: () => Promise<GeneratedSessionTitle | null>;
|
|
25
55
|
cancel: () => Promise<void>;
|
|
@@ -46,6 +46,7 @@ export type PrepareTurnToolRuntimeDeps = {
|
|
|
46
46
|
turnExecutionPolicy: ClaimTurnOk["turnExecutionPolicy"];
|
|
47
47
|
trigger: ClaimTurnOk["trigger"];
|
|
48
48
|
runSettings: GovernanceModelOk["runSettings"];
|
|
49
|
+
resolvedModel: GovernanceModelOk["resolvedModel"];
|
|
49
50
|
lazyToolTransport: GovernanceModelOk["lazyToolTransport"];
|
|
50
51
|
turnTools: ReturnType<typeof withFirstPartyTools>;
|
|
51
52
|
connectionScope: {
|
|
@@ -60,6 +61,8 @@ export type PrepareTurnToolRuntimeDeps = {
|
|
|
60
61
|
credentialSubjectId: ClaimTurnOk["credentialSubjectId"];
|
|
61
62
|
interactionInterventionResume: ClaimTurnOk["interactionInterventionResume"];
|
|
62
63
|
runWorkspaceMutationForSandbox: SandboxTurnRuntime["runWorkspaceMutationForSandbox"];
|
|
64
|
+
/** Deployment and workspace allow the Jev-backed code_search tool. */
|
|
65
|
+
codeSearchEnabled: boolean;
|
|
63
66
|
throwIfWorkerShuttingDown: () => void;
|
|
64
67
|
throwIfTurnCancelled: () => void;
|
|
65
68
|
};
|
|
@@ -162,6 +165,7 @@ export declare function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps)
|
|
|
162
165
|
generateSessionTitleInParallel: boolean;
|
|
163
166
|
postToolPreparationStartedAt: number;
|
|
164
167
|
preparationIndependentToolNames: string[];
|
|
168
|
+
codeSearchAvailable: boolean;
|
|
165
169
|
skillCatalog: {
|
|
166
170
|
id: string;
|
|
167
171
|
name: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Database } from "@opengeni/db";
|
|
2
|
-
import { type CompactionItem, type CompactionProviderRejection } from "@opengeni/runtime";
|
|
2
|
+
import { prepareCompactionPromptInput, type CompactionItem, type CompactionProviderRejection } from "@opengeni/runtime";
|
|
3
3
|
import { type Settings } from "@opengeni/config";
|
|
4
4
|
import type { SessionEvent } from "@opengeni/contracts";
|
|
5
5
|
export type MaybeCompactResult = {
|
|
@@ -28,7 +28,10 @@ export type MaybeCompactResult = {
|
|
|
28
28
|
* Codex, call Codex `/codex/responses` with `compaction_trigger` and persist the
|
|
29
29
|
* opaque compaction item. Fail closed — never silently fall back to portable.
|
|
30
30
|
*/
|
|
31
|
-
export type CompactionSummarizer = (settings: Settings, input: CompactionItem[]) => Promise<string
|
|
31
|
+
export type CompactionSummarizer = ((settings: Settings, input: CompactionItem[]) => Promise<string>) & {
|
|
32
|
+
/** Model-visible instructions and tool schemas outside the history estimate. */
|
|
33
|
+
estimatePrefixTokens?: () => number;
|
|
34
|
+
};
|
|
32
35
|
/** Returns the opaque Codex remote compaction v2 item. */
|
|
33
36
|
export type RemoteCompactionV2Requester = (settings: Settings, input: CompactionItem[]) => Promise<CompactionItem>;
|
|
34
37
|
export declare function maybeCompactContext(db: Database, settings: Settings, scope: {
|
|
@@ -86,5 +89,10 @@ export declare function settleFailedContextCompactionLandmark(db: Database, scop
|
|
|
86
89
|
}): Promise<Extract<MaybeCompactResult, {
|
|
87
90
|
compacted: false;
|
|
88
91
|
}>>;
|
|
92
|
+
export declare function summarizeWithCodexOverflowTrimming(summarize: CompactionSummarizer, settings: Settings, activeHistory: CompactionItem[]): Promise<{
|
|
93
|
+
summaryBody: string;
|
|
94
|
+
preparation: ReturnType<typeof prepareCompactionPromptInput>;
|
|
95
|
+
providerCalls: number;
|
|
96
|
+
}>;
|
|
89
97
|
export declare function isContextWindowExceeded(error: unknown, seen?: WeakSet<object>): boolean;
|
|
90
98
|
export declare function isExactContextLengthExceeded(error: unknown, seen?: WeakSet<object>): boolean;
|
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import type { DocumentServices } from "@opengeni/documents";
|
|
2
2
|
import type { ControlActivityServices } from "./types.js";
|
|
3
|
+
/** The configured monthly indexed-chunk limit, not a provider failure. */
|
|
4
|
+
export declare class KnowledgeIndexUsageLimitError extends Error {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
export type KnowledgeIndexFailureStage = "embedding" | "processing";
|
|
8
|
+
/**
|
|
9
|
+
* Content-free classification for a deferred Knowledge index batch. Only
|
|
10
|
+
* protocol constants, an HTTP status, and a PostgreSQL SQLSTATE are retained;
|
|
11
|
+
* provider messages, bodies, SQL, and identifiers never leave the process.
|
|
12
|
+
* Outside the embedding call, only a PostgreSQL error in the cause chain is
|
|
13
|
+
* attributed to the database; any other failure stays a worker failure.
|
|
14
|
+
*/
|
|
15
|
+
export declare function knowledgeIndexFailureDiagnostic(stage: KnowledgeIndexFailureStage, error: unknown): {
|
|
16
|
+
errorClass: "KnowledgeIndexOperationError";
|
|
17
|
+
errorCode: "knowledge_index_usage_limit_reached" | "knowledge_index_embedding_failed" | "knowledge_index_persistence_failed" | "knowledge_index_failed";
|
|
18
|
+
origin: "worker" | "db";
|
|
19
|
+
status?: number;
|
|
20
|
+
sqlState?: string;
|
|
21
|
+
};
|
|
3
22
|
export declare function createKnowledgeIndexingActivities(services: () => Promise<ControlActivityServices>, resolveDocumentServices?: () => Promise<DocumentServices>): {
|
|
4
23
|
indexKnowledge: () => Promise<{
|
|
5
24
|
completed: number;
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
warnDrainSnapshotFailure,
|
|
34
34
|
withFirstPartyTools,
|
|
35
35
|
workflowIdForSession
|
|
36
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-7M6G2SCF.js";
|
|
37
37
|
import {
|
|
38
38
|
inspectOpenSandboxKubernetesInventory,
|
|
39
39
|
recordCreditBalanceGauges,
|
|
@@ -53,7 +53,7 @@ import {
|
|
|
53
53
|
recordTurnsQueuedGauge,
|
|
54
54
|
recordWorkerDeathRecoveryMetrics,
|
|
55
55
|
runtimeMetricsHooksForObservability
|
|
56
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-DSPP6CZL.js";
|
|
57
57
|
import "./chunk-PZ5AY32C.js";
|
|
58
58
|
|
|
59
59
|
// src/activities/knowledge-indexing.ts
|
|
@@ -76,6 +76,64 @@ import {
|
|
|
76
76
|
withWorkspaceUsageLock,
|
|
77
77
|
waitKnowledgeIndexForFunding
|
|
78
78
|
} from "@opengeni/db";
|
|
79
|
+
var KnowledgeIndexUsageLimitError = class extends Error {
|
|
80
|
+
constructor() {
|
|
81
|
+
super("monthly document indexing limit reached");
|
|
82
|
+
this.name = "KnowledgeIndexUsageLimitError";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function knowledgeIndexFailureDiagnostic(stage, error) {
|
|
86
|
+
if (error instanceof KnowledgeIndexUsageLimitError) {
|
|
87
|
+
return {
|
|
88
|
+
errorClass: "KnowledgeIndexOperationError",
|
|
89
|
+
errorCode: "knowledge_index_usage_limit_reached",
|
|
90
|
+
origin: "worker"
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (stage === "embedding") {
|
|
94
|
+
const status = ownValue(error, "status");
|
|
95
|
+
return {
|
|
96
|
+
errorClass: "KnowledgeIndexOperationError",
|
|
97
|
+
errorCode: "knowledge_index_embedding_failed",
|
|
98
|
+
origin: "worker",
|
|
99
|
+
...typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599 ? { status } : {}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const postgres = postgresErrorState(error);
|
|
103
|
+
if (!postgres) {
|
|
104
|
+
return {
|
|
105
|
+
errorClass: "KnowledgeIndexOperationError",
|
|
106
|
+
errorCode: "knowledge_index_failed",
|
|
107
|
+
origin: "worker"
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
errorClass: "KnowledgeIndexOperationError",
|
|
112
|
+
errorCode: "knowledge_index_persistence_failed",
|
|
113
|
+
origin: "db",
|
|
114
|
+
...postgres.sqlState ? { sqlState: postgres.sqlState } : {}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function ownValue(value, key) {
|
|
118
|
+
try {
|
|
119
|
+
if (!value || typeof value !== "object") return void 0;
|
|
120
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
121
|
+
return descriptor && "value" in descriptor ? descriptor.value : void 0;
|
|
122
|
+
} catch {
|
|
123
|
+
return void 0;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function postgresErrorState(error) {
|
|
127
|
+
let current = error;
|
|
128
|
+
for (let depth = 0; depth < 4 && current && typeof current === "object"; depth += 1) {
|
|
129
|
+
if (ownValue(current, "name") === "PostgresError") {
|
|
130
|
+
const code = ownValue(current, "code");
|
|
131
|
+
return typeof code === "string" && /^[0-9A-Z]{5}$/.test(code) ? { sqlState: code } : {};
|
|
132
|
+
}
|
|
133
|
+
current = ownValue(current, "cause");
|
|
134
|
+
}
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
79
137
|
function createKnowledgeIndexingActivities(services, resolveDocumentServices) {
|
|
80
138
|
let activationTime;
|
|
81
139
|
return {
|
|
@@ -103,6 +161,7 @@ function createKnowledgeIndexingActivities(services, resolveDocumentServices) {
|
|
|
103
161
|
limit: 2
|
|
104
162
|
});
|
|
105
163
|
for (const claim of claims) {
|
|
164
|
+
let stage = "processing";
|
|
106
165
|
try {
|
|
107
166
|
const source = await readKnowledgeIndexSource(db, claim);
|
|
108
167
|
if (!source) {
|
|
@@ -167,8 +226,7 @@ function createKnowledgeIndexingActivities(services, resolveDocumentServices) {
|
|
|
167
226
|
eventType: "document.indexed",
|
|
168
227
|
since: new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1))
|
|
169
228
|
});
|
|
170
|
-
if (used + chunks.length > limit)
|
|
171
|
-
throw new Error("monthly document indexing limit reached");
|
|
229
|
+
if (used + chunks.length > limit) throw new KnowledgeIndexUsageLimitError();
|
|
172
230
|
}
|
|
173
231
|
}
|
|
174
232
|
const inputs = chunks.map((chunk) => chunk.embeddingInput);
|
|
@@ -176,9 +234,11 @@ function createKnowledgeIndexingActivities(services, resolveDocumentServices) {
|
|
|
176
234
|
(sum, input) => sum + Buffer.byteLength(input, "utf8"),
|
|
177
235
|
0
|
|
178
236
|
);
|
|
237
|
+
stage = "embedding";
|
|
179
238
|
const vectors = await embedder.embedMany(inputs);
|
|
180
239
|
if (vectors.length !== chunks.length)
|
|
181
240
|
throw new Error("Incomplete Knowledge embeddings");
|
|
241
|
+
stage = "processing";
|
|
182
242
|
if (paid) {
|
|
183
243
|
const publication = await guardPaidKnowledgeIndexPublication(lockedDb, claim);
|
|
184
244
|
if (publication !== "published") {
|
|
@@ -276,14 +336,19 @@ function createKnowledgeIndexingActivities(services, resolveDocumentServices) {
|
|
|
276
336
|
else result.unavailable++;
|
|
277
337
|
}
|
|
278
338
|
});
|
|
279
|
-
} catch {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
339
|
+
} catch (error) {
|
|
340
|
+
observability.warn(
|
|
341
|
+
"Knowledge indexing batch deferred",
|
|
342
|
+
knowledgeIndexFailureDiagnostic(stage, error)
|
|
343
|
+
);
|
|
344
|
+
await deferKnowledgeIndexJob(db, claim).catch((deferError) => {
|
|
345
|
+
const deferDiagnostic = knowledgeIndexFailureDiagnostic("processing", deferError);
|
|
346
|
+
observability.warn("Knowledge indexing batch deferral failed", {
|
|
347
|
+
...deferDiagnostic,
|
|
348
|
+
errorCode: "knowledge_index_defer_failed"
|
|
349
|
+
});
|
|
286
350
|
});
|
|
351
|
+
result.deferred++;
|
|
287
352
|
}
|
|
288
353
|
}
|
|
289
354
|
return result;
|
|
@@ -4763,6 +4828,7 @@ import {
|
|
|
4763
4828
|
openGeniSlackBotMetadata,
|
|
4764
4829
|
requireOpenGeniSlackBotConnection,
|
|
4765
4830
|
resolveWorkspaceCatalogSettings as resolveWorkspaceCatalogSettings2,
|
|
4831
|
+
resolveScheduledTaskDefaultModel,
|
|
4766
4832
|
resolveSessionToolPolicy,
|
|
4767
4833
|
workspaceCustomModelReference,
|
|
4768
4834
|
lockActiveCustomModelForAdmission,
|
|
@@ -5127,8 +5193,9 @@ function createScheduledTaskActivities(services) {
|
|
|
5127
5193
|
taskAuthoritySubjectId
|
|
5128
5194
|
) : null;
|
|
5129
5195
|
const settings = await settingsForTask(task, targetSessionExecutionBase?.model);
|
|
5130
|
-
const
|
|
5131
|
-
const
|
|
5196
|
+
const resolvedDefault = task.agentConfig.model || targetSessionExecutionBase ? null : await resolveScheduledTaskDefaultModel(db, settings, task);
|
|
5197
|
+
const model = task.agentConfig.model ?? resolvedDefault?.model ?? settings.openaiModel;
|
|
5198
|
+
const reasoningEffort = task.agentConfig.reasoningEffort ?? resolvedDefault?.reasoningEffort ?? settings.openaiReasoningEffort;
|
|
5132
5199
|
let sandboxBackend = task.agentConfig.sandboxBackend ?? settings.sandboxBackend;
|
|
5133
5200
|
let sandboxOs = "linux";
|
|
5134
5201
|
const taskTools = withFirstPartyTools(settings, task.agentConfig.tools);
|
|
@@ -7679,4 +7746,4 @@ export {
|
|
|
7679
7746
|
createControlActivities,
|
|
7680
7747
|
createControlActivitiesFromServices
|
|
7681
7748
|
};
|
|
7682
|
-
//# sourceMappingURL=activities-control-
|
|
7749
|
+
//# sourceMappingURL=activities-control-I72CRMAE.js.map
|