@keystrokehq/keystroke 0.1.36 → 0.1.37

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/config.d.cts CHANGED
@@ -1258,8 +1258,8 @@ type KeystrokeConfig = {
1258
1258
  plugins?: ServerPlugin[];
1259
1259
  dirs?: KeystrokeModuleDirs; /** Queue backend for queued execution. Defaults to pg-boss (Postgres) or DB polling (SQLite). */
1260
1260
  scheduler?: SchedulerPlugin;
1261
- server?: KeystrokeServerConfig; /** Platform project slug this directory deploys to. Optional; set via `keystroke project link`. */
1262
- project?: string; /** Platform organization slug. Optional; usually auto-filled by `keystroke project link`. */
1261
+ server?: KeystrokeServerConfig; /** Platform project slug this directory deploys to. Optional; set via `keystroke projects link`. */
1262
+ project?: string; /** Platform organization slug. Optional; usually auto-filled by `keystroke projects link`. */
1263
1263
  organization?: string;
1264
1264
  };
1265
1265
  type CreatePluginContextOptions = {
package/dist/config.d.mts CHANGED
@@ -1258,8 +1258,8 @@ type KeystrokeConfig = {
1258
1258
  plugins?: ServerPlugin[];
1259
1259
  dirs?: KeystrokeModuleDirs; /** Queue backend for queued execution. Defaults to pg-boss (Postgres) or DB polling (SQLite). */
1260
1260
  scheduler?: SchedulerPlugin;
1261
- server?: KeystrokeServerConfig; /** Platform project slug this directory deploys to. Optional; set via `keystroke project link`. */
1262
- project?: string; /** Platform organization slug. Optional; usually auto-filled by `keystroke project link`. */
1261
+ server?: KeystrokeServerConfig; /** Platform project slug this directory deploys to. Optional; set via `keystroke projects link`. */
1262
+ project?: string; /** Platform organization slug. Optional; usually auto-filled by `keystroke projects link`. */
1263
1263
  organization?: string;
1264
1264
  };
1265
1265
  type CreatePluginContextOptions = {
@@ -6889,7 +6889,7 @@ var require_get_vercel_oidc_token = /* @__PURE__ */ __commonJSMin(((exports, mod
6889
6889
  err = error;
6890
6890
  }
6891
6891
  try {
6892
- const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([await Promise.resolve().then(() => /* @__PURE__ */ __toESM(require_token_util())), await import("./token-DUN0yjzi.mjs").then((m) => /* @__PURE__ */ __toESM(m.default))]);
6892
+ const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([await Promise.resolve().then(() => /* @__PURE__ */ __toESM(require_token_util())), await import("./token-CJ2Rrkyp.mjs").then((m) => /* @__PURE__ */ __toESM(m.default))]);
6893
6893
  if (!token || isExpired(getTokenPayload(token), options?.expirationBufferMs)) {
6894
6894
  await refreshToken(options);
6895
6895
  token = getVercelOidcTokenSync();
@@ -12427,6 +12427,12 @@ function createRestrictedTelemetryDispatcher({ telemetry, includeRuntimeContext,
12427
12427
  function isStepCount(stepCount) {
12428
12428
  return ({ steps }) => steps.length === stepCount;
12429
12429
  }
12430
+ function hasToolCall(...toolName) {
12431
+ return ({ steps }) => {
12432
+ var _a22, _b, _c;
12433
+ return (_c = (_b = (_a22 = steps[steps.length - 1]) == null ? void 0 : _a22.toolCalls) == null ? void 0 : _b.some((toolCall) => toolName.includes(toolCall.toolName))) != null ? _c : false;
12434
+ };
12435
+ }
12430
12436
  async function isStopConditionMet({ stopConditions, steps }) {
12431
12437
  return (await Promise.all(stopConditions.map((condition) => condition({ steps })))).some((result) => result);
12432
12438
  }
@@ -17294,6 +17300,169 @@ createIdGenerator({
17294
17300
  prefix: "aiobj",
17295
17301
  size: 24
17296
17302
  });
17303
+ function defaultTransform(text2) {
17304
+ return text2.replace(/^```(?:json)?\s*\n?/, "").replace(/\n?```\s*$/, "").trim();
17305
+ }
17306
+ function extractJsonMiddleware(options) {
17307
+ var _a22;
17308
+ const transform = (_a22 = options == null ? void 0 : options.transform) != null ? _a22 : defaultTransform;
17309
+ const hasCustomTransform = (options == null ? void 0 : options.transform) !== void 0;
17310
+ return {
17311
+ specificationVersion: "v4",
17312
+ wrapGenerate: async ({ doGenerate }) => {
17313
+ const { content, ...rest } = await doGenerate();
17314
+ const transformedContent = [];
17315
+ for (const part of content) {
17316
+ if (part.type !== "text") {
17317
+ transformedContent.push(part);
17318
+ continue;
17319
+ }
17320
+ transformedContent.push({
17321
+ ...part,
17322
+ text: transform(part.text)
17323
+ });
17324
+ }
17325
+ return {
17326
+ content: transformedContent,
17327
+ ...rest
17328
+ };
17329
+ },
17330
+ wrapStream: async ({ doStream }) => {
17331
+ const { stream, ...rest } = await doStream();
17332
+ const textBlocks = createIdMap();
17333
+ const SUFFIX_BUFFER_SIZE = 12;
17334
+ return {
17335
+ stream: stream.pipeThrough(new TransformStream({ transform: (chunk, controller) => {
17336
+ if (chunk.type === "text-start") {
17337
+ textBlocks[chunk.id] = {
17338
+ startEvent: chunk,
17339
+ phase: hasCustomTransform ? "buffering" : "prefix",
17340
+ buffer: "",
17341
+ prefixStripped: false
17342
+ };
17343
+ return;
17344
+ }
17345
+ if (chunk.type === "text-delta") {
17346
+ const block = textBlocks[chunk.id];
17347
+ if (!block) {
17348
+ controller.enqueue(chunk);
17349
+ return;
17350
+ }
17351
+ block.buffer += chunk.delta;
17352
+ if (block.phase === "buffering") return;
17353
+ if (block.phase === "prefix") {
17354
+ if (block.buffer.length > 0 && !block.buffer.startsWith("`")) {
17355
+ block.phase = "streaming";
17356
+ controller.enqueue(block.startEvent);
17357
+ } else if (block.buffer.startsWith("```")) {
17358
+ if (block.buffer.includes("\n")) {
17359
+ const prefixMatch = block.buffer.match(/^```(?:json)?\s*\n/);
17360
+ if (prefixMatch) {
17361
+ block.buffer = block.buffer.slice(prefixMatch[0].length);
17362
+ block.prefixStripped = true;
17363
+ block.phase = "streaming";
17364
+ controller.enqueue(block.startEvent);
17365
+ } else {
17366
+ block.phase = "streaming";
17367
+ controller.enqueue(block.startEvent);
17368
+ }
17369
+ }
17370
+ } else if (block.buffer.length >= 3 && !block.buffer.startsWith("```")) {
17371
+ block.phase = "streaming";
17372
+ controller.enqueue(block.startEvent);
17373
+ }
17374
+ }
17375
+ if (block.phase === "streaming" && block.buffer.length > SUFFIX_BUFFER_SIZE) {
17376
+ const toStream = block.buffer.slice(0, -12);
17377
+ block.buffer = block.buffer.slice(-12);
17378
+ controller.enqueue({
17379
+ type: "text-delta",
17380
+ id: chunk.id,
17381
+ delta: toStream
17382
+ });
17383
+ }
17384
+ return;
17385
+ }
17386
+ if (chunk.type === "text-end") {
17387
+ const block = textBlocks[chunk.id];
17388
+ if (block) {
17389
+ if (block.phase === "prefix" || block.phase === "buffering") controller.enqueue(block.startEvent);
17390
+ let remaining = block.buffer;
17391
+ if (block.phase === "buffering") remaining = transform(remaining);
17392
+ else if (block.prefixStripped) remaining = remaining.replace(/\n?```\s*$/, "").trimEnd();
17393
+ else remaining = transform(remaining);
17394
+ if (remaining.length > 0) controller.enqueue({
17395
+ type: "text-delta",
17396
+ id: chunk.id,
17397
+ delta: remaining
17398
+ });
17399
+ controller.enqueue(chunk);
17400
+ delete textBlocks[chunk.id];
17401
+ return;
17402
+ }
17403
+ }
17404
+ controller.enqueue(chunk);
17405
+ } })),
17406
+ ...rest
17407
+ };
17408
+ }
17409
+ };
17410
+ }
17411
+ var wrapLanguageModel = ({ model: inputModel, middleware: middlewareArg, modelId, providerId }) => {
17412
+ const model = asLanguageModelV4(inputModel);
17413
+ return [...asArray(middlewareArg)].reverse().reduce((wrappedModel, middleware) => {
17414
+ return doWrap({
17415
+ model: wrappedModel,
17416
+ middleware,
17417
+ modelId,
17418
+ providerId
17419
+ });
17420
+ }, model);
17421
+ };
17422
+ var doWrap = ({ model, middleware: { transformParams, wrapGenerate, wrapStream, overrideProvider, overrideModelId, overrideSupportedUrls }, modelId, providerId }) => {
17423
+ var _a22, _b, _c;
17424
+ async function doTransform({ params, type }) {
17425
+ return transformParams ? await transformParams({
17426
+ params,
17427
+ type,
17428
+ model
17429
+ }) : params;
17430
+ }
17431
+ return {
17432
+ specificationVersion: "v4",
17433
+ provider: (_a22 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a22 : model.provider,
17434
+ modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
17435
+ supportedUrls: (_c = overrideSupportedUrls == null ? void 0 : overrideSupportedUrls({ model })) != null ? _c : model.supportedUrls,
17436
+ async doGenerate(params) {
17437
+ const transformedParams = await doTransform({
17438
+ params,
17439
+ type: "generate"
17440
+ });
17441
+ const doGenerate = async () => await model.doGenerate(transformedParams);
17442
+ const doStream = async () => await model.doStream(transformedParams);
17443
+ return wrapGenerate ? await wrapGenerate({
17444
+ doGenerate,
17445
+ doStream,
17446
+ params: transformedParams,
17447
+ model
17448
+ }) : await doGenerate();
17449
+ },
17450
+ async doStream(params) {
17451
+ const transformedParams = await doTransform({
17452
+ params,
17453
+ type: "stream"
17454
+ });
17455
+ const doGenerate = async () => await model.doGenerate(transformedParams);
17456
+ const doStream = async () => await model.doStream(transformedParams);
17457
+ return wrapStream ? await wrapStream({
17458
+ doGenerate,
17459
+ doStream,
17460
+ params: transformedParams,
17461
+ model
17462
+ }) : await doStream();
17463
+ }
17464
+ };
17465
+ };
17297
17466
  createIdGenerator({
17298
17467
  prefix: "call",
17299
17468
  size: 24
@@ -46974,6 +47143,6 @@ function resolveWorkflowTool(workflow, context = {}) {
46974
47143
  });
46975
47144
  }
46976
47145
  //#endregion
46977
- export { resolveRunSourceFromTraceContext as $, generateObject as A, jsonSchema as B, connectMcpDefinition as C, isMcp as D, defineMcp as E, toUIMessageStream as F, clearLiveMessage as G, MESSAGE_EVENT_TYPE as H, createGateway as I, getAgentByRoute as J, createSession as K, require_token_util as L, isFileUIPart as M, output_exports as N, ToolLoopAgent as O, readUIMessageStream as P, recordLlmUsageFromAssistantMessage as Q, require_token_error as R, withCredentialAssignments as S, connectMcpStdio as T, addAgentSessionDuration as U, tool as V, appendEvent as W, getSession as X, getProjectScopeId as Y, listMessageEvents as Z, createCredentialResolver as _, defineWorkflow as a, withSpan as at, resolveActionCredentials as b, isRunCanceledError as c, registerWorkflowToolExecutor as d, setSessionLiveMessage as et, resolveWorkflowTool as f, captureCredentialToolErrors as g, buildCredentialRunContext as h, createDirectActionRunner as i, getTraceContext as it, generateText as j, convertToModelMessages as k, isWorkflow as l, serializeWorkflowError as m, RunCanceledError as n, touchSession as nt, deserializeWorkflowError as o, runWithWorkflowContext as p, failAgentSession as q, createActionRunner as r, captureConsole as rt, executeWorkflow as s, MemoryEventLog as t, setSessionTitle as tt, promptLlm as u, enrichCredentialError as v, connectMcpServer as w, resolveMcpTools as x, isCredentialError as y, generateId as z };
47146
+ export { getSession as $, extractJsonMiddleware as A, require_token_util as B, connectMcpDefinition as C, isMcp as D, defineMcp as E, output_exports as F, MESSAGE_EVENT_TYPE as G, generateId as H, readUIMessageStream as I, clearLiveMessage as J, addAgentSessionDuration as K, toUIMessageStream as L, generateText as M, hasToolCall as N, ToolLoopAgent as O, isFileUIPart as P, getProjectScopeId as Q, wrapLanguageModel as R, withCredentialAssignments as S, connectMcpStdio as T, jsonSchema as U, require_token_error as V, tool as W, failAgentSession as X, createSession as Y, getAgentByRoute as Z, createCredentialResolver as _, defineWorkflow as a, touchSession as at, resolveActionCredentials as b, isRunCanceledError as c, withSpan as ct, registerWorkflowToolExecutor as d, listMessageEvents as et, resolveWorkflowTool as f, captureCredentialToolErrors as g, buildCredentialRunContext as h, createDirectActionRunner as i, setSessionTitle as it, generateObject as j, convertToModelMessages as k, isWorkflow as l, serializeWorkflowError as m, RunCanceledError as n, resolveRunSourceFromTraceContext as nt, deserializeWorkflowError as o, captureConsole as ot, runWithWorkflowContext as p, appendEvent as q, createActionRunner as r, setSessionLiveMessage as rt, executeWorkflow as s, getTraceContext as st, MemoryEventLog as t, recordLlmUsageFromAssistantMessage as tt, promptLlm as u, enrichCredentialError as v, connectMcpServer as w, resolveMcpTools as x, isCredentialError as y, createGateway as z };
46978
47147
 
46979
- //# sourceMappingURL=dist-iDcp4e6O.mjs.map
47148
+ //# sourceMappingURL=dist-1heZMRTe.mjs.map