@tangle-network/create-agent-app 0.62.4 → 0.63.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/package.json +1 -1
- package/template-chat/src/chat.ts +11 -9
- package/template-chat/src/sandbox.ts +29 -27
package/package.json
CHANGED
|
@@ -116,7 +116,7 @@ export function buildChatApp(env: AppEnv, overrides: ChatAppOverrides = {}): Cha
|
|
|
116
116
|
* `userId`/`workspaceId`. */
|
|
117
117
|
async function authorize(args: {
|
|
118
118
|
request: Request
|
|
119
|
-
intent: 'turn' | 'replay' | 'running'
|
|
119
|
+
intent: 'turn' | 'replay' | 'running' | 'cancel'
|
|
120
120
|
body?: Record<string, unknown>
|
|
121
121
|
threadId?: string
|
|
122
122
|
}): Promise<ChatTurnAuthorization<void>> {
|
|
@@ -146,7 +146,15 @@ export function buildChatApp(env: AppEnv, overrides: ChatAppOverrides = {}): Cha
|
|
|
146
146
|
interface Admission { handle: unknown; started: boolean; producer?: ChatTurnRouteProducer; userMessageId?: string }
|
|
147
147
|
const admissions = new Map<string, Admission>()
|
|
148
148
|
const lane = overrides.produce ? null : createHybridLane(env)
|
|
149
|
-
|
|
149
|
+
// Native Sandbox execution keeps the backend-terminal ownership check.
|
|
150
|
+
// Router option data goes directly to the shared route before its lock.
|
|
151
|
+
const nativeProduce = async (args: ChatTurnProduceArgs<void>) => {
|
|
152
|
+
const admission = admissions.get(args.executionId)
|
|
153
|
+
if (!admission) throw new Error('Turn admission is unavailable')
|
|
154
|
+
admission.started = true
|
|
155
|
+
admission.producer = await (overrides.produce ?? lane!.produce.sandbox)(args)
|
|
156
|
+
return admission.producer
|
|
157
|
+
}
|
|
150
158
|
const routes = createChatTurnRoutes<void>({
|
|
151
159
|
turnLock: {
|
|
152
160
|
acquire: async args => {
|
|
@@ -182,13 +190,7 @@ export function buildChatApp(env: AppEnv, overrides: ChatAppOverrides = {}): Cha
|
|
|
182
190
|
await store.updateMessage(args.userMessageId, { extras: { turnStreamId: args.turnStreamId, backendTerminal: false } })
|
|
183
191
|
}
|
|
184
192
|
},
|
|
185
|
-
produce:
|
|
186
|
-
const admission = admissions.get(args.executionId)
|
|
187
|
-
if (!admission) throw new Error('Turn admission is unavailable')
|
|
188
|
-
admission.started = true
|
|
189
|
-
admission.producer = await produce(args)
|
|
190
|
-
return admission.producer
|
|
191
|
-
},
|
|
193
|
+
produce: overrides.produce ? nativeProduce : { ...lane!.produce, sandbox: nativeProduce },
|
|
192
194
|
interactions: {
|
|
193
195
|
resolveConnection: async ({ request, intent, body }) => {
|
|
194
196
|
const session = await requireUser(request)
|
|
@@ -18,16 +18,14 @@
|
|
|
18
18
|
|
|
19
19
|
import { config } from '../agent.config'
|
|
20
20
|
import {
|
|
21
|
-
createHybridTurnProducer,
|
|
22
21
|
createSandboxChatProducer,
|
|
23
22
|
normalizeChatPromptForSandbox,
|
|
24
|
-
routerTurnHistory,
|
|
25
23
|
startHybridBox,
|
|
26
24
|
turnCarriesFiles,
|
|
27
|
-
turnPromptText,
|
|
28
25
|
type ChatTurnAfterAuthorizeArgs,
|
|
29
26
|
type ChatTurnProduceArgs,
|
|
30
27
|
type ChatTurnRouteProducer,
|
|
28
|
+
type ChatTurnHybridConfiguration,
|
|
31
29
|
type SandboxUploadSink,
|
|
32
30
|
} from '@tangle-network/agent-app/chat-routes'
|
|
33
31
|
import type { SidecarInteractionsConnection } from '@tangle-network/agent-app/interactions'
|
|
@@ -207,30 +205,34 @@ export function createHybridLane(env: AppEnv) {
|
|
|
207
205
|
// A turn that ends before `produce` leaves the box to idle out.
|
|
208
206
|
return () => { started.delete(threadId) }
|
|
209
207
|
},
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
}
|
|
208
|
+
produce: {
|
|
209
|
+
when: ({ prompt }: ChatTurnProduceArgs<void>) => Boolean(env.TANGLE_API_KEY?.trim()) && !turnCarriesFiles(prompt),
|
|
210
|
+
router(args: ChatTurnProduceArgs<void>): ChatTurnHybridConfiguration {
|
|
211
|
+
const { body, identity, trace } = args
|
|
212
|
+
const box = started.get(identity.sessionId)
|
|
213
|
+
started.delete(identity.sessionId)
|
|
214
|
+
const apiKey = env.TANGLE_API_KEY?.trim()
|
|
215
|
+
if (!apiKey) throw new Error('Router credentials are not configured')
|
|
216
|
+
const model = body.model ?? env.MODEL_NAME ?? config.model.default
|
|
217
|
+
const baseUrl = routerBaseUrl(env)
|
|
218
|
+
const scope = { workspaceId: identity.tenantId, userId: identity.userId }
|
|
219
|
+
return {
|
|
220
|
+
apiKey,
|
|
221
|
+
model,
|
|
222
|
+
...(baseUrl ? { baseUrl } : {}),
|
|
223
|
+
systemPrompt: { profile: { prompt: { systemPrompt: config.systemPrompt } } },
|
|
224
|
+
box: {
|
|
225
|
+
acquire: () => acquire(scope, trace),
|
|
226
|
+
...(box ? { started: box } : {}),
|
|
227
|
+
// The box agent keeps its own session per thread, so a sandbox-lane turn on the same thread never collides with it.
|
|
228
|
+
runTask: sandboxPromptRunner(shell, { model, harness: config.harness, sessionId: `sandbox-run-${identity.sessionId}` }),
|
|
229
|
+
},
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
sandbox(args: ChatTurnProduceArgs<void>) {
|
|
233
|
+
started.delete(args.identity.sessionId)
|
|
234
|
+
return sandboxProduce(args)
|
|
235
|
+
},
|
|
234
236
|
},
|
|
235
237
|
}
|
|
236
238
|
}
|