@keystrokehq/keystroke 0.1.36 → 0.1.38

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 = {
@@ -3277,6 +3277,7 @@ const triggers = pgTable("triggers", {
3277
3277
  moduleFile: text$2("module_file").notNull(),
3278
3278
  origin: text$2("origin").$type().notNull().default("project"),
3279
3279
  config: jsonb("config").$type(),
3280
+ state: jsonb("state").$type(),
3280
3281
  schedule: text$2("schedule"),
3281
3282
  nextRunAt: timestamp("next_run_at", { withTimezone: true }),
3282
3283
  enabled: integer$1("enabled").notNull().default(1),
@@ -3302,6 +3303,7 @@ const triggersSqlite = sqliteTable("triggers", {
3302
3303
  moduleFile: text$1("module_file").notNull(),
3303
3304
  origin: text$1("origin").$type().notNull().default("project"),
3304
3305
  config: text$1("config", { mode: "json" }).$type(),
3306
+ state: text$1("state", { mode: "json" }).$type(),
3305
3307
  schedule: text$1("schedule"),
3306
3308
  nextRunAt: integer("next_run_at", { mode: "timestamp_ms" }),
3307
3309
  enabled: integer("enabled").notNull().default(1),
@@ -6889,7 +6891,7 @@ var require_get_vercel_oidc_token = /* @__PURE__ */ __commonJSMin(((exports, mod
6889
6891
  err = error;
6890
6892
  }
6891
6893
  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))]);
6894
+ const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([await Promise.resolve().then(() => /* @__PURE__ */ __toESM(require_token_util())), await import("./token-1esrncEC.mjs").then((m) => /* @__PURE__ */ __toESM(m.default))]);
6893
6895
  if (!token || isExpired(getTokenPayload(token), options?.expirationBufferMs)) {
6894
6896
  await refreshToken(options);
6895
6897
  token = getVercelOidcTokenSync();
@@ -12427,6 +12429,12 @@ function createRestrictedTelemetryDispatcher({ telemetry, includeRuntimeContext,
12427
12429
  function isStepCount(stepCount) {
12428
12430
  return ({ steps }) => steps.length === stepCount;
12429
12431
  }
12432
+ function hasToolCall(...toolName) {
12433
+ return ({ steps }) => {
12434
+ var _a22, _b, _c;
12435
+ 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;
12436
+ };
12437
+ }
12430
12438
  async function isStopConditionMet({ stopConditions, steps }) {
12431
12439
  return (await Promise.all(stopConditions.map((condition) => condition({ steps })))).some((result) => result);
12432
12440
  }
@@ -17294,6 +17302,169 @@ createIdGenerator({
17294
17302
  prefix: "aiobj",
17295
17303
  size: 24
17296
17304
  });
17305
+ function defaultTransform(text2) {
17306
+ return text2.replace(/^```(?:json)?\s*\n?/, "").replace(/\n?```\s*$/, "").trim();
17307
+ }
17308
+ function extractJsonMiddleware(options) {
17309
+ var _a22;
17310
+ const transform = (_a22 = options == null ? void 0 : options.transform) != null ? _a22 : defaultTransform;
17311
+ const hasCustomTransform = (options == null ? void 0 : options.transform) !== void 0;
17312
+ return {
17313
+ specificationVersion: "v4",
17314
+ wrapGenerate: async ({ doGenerate }) => {
17315
+ const { content, ...rest } = await doGenerate();
17316
+ const transformedContent = [];
17317
+ for (const part of content) {
17318
+ if (part.type !== "text") {
17319
+ transformedContent.push(part);
17320
+ continue;
17321
+ }
17322
+ transformedContent.push({
17323
+ ...part,
17324
+ text: transform(part.text)
17325
+ });
17326
+ }
17327
+ return {
17328
+ content: transformedContent,
17329
+ ...rest
17330
+ };
17331
+ },
17332
+ wrapStream: async ({ doStream }) => {
17333
+ const { stream, ...rest } = await doStream();
17334
+ const textBlocks = createIdMap();
17335
+ const SUFFIX_BUFFER_SIZE = 12;
17336
+ return {
17337
+ stream: stream.pipeThrough(new TransformStream({ transform: (chunk, controller) => {
17338
+ if (chunk.type === "text-start") {
17339
+ textBlocks[chunk.id] = {
17340
+ startEvent: chunk,
17341
+ phase: hasCustomTransform ? "buffering" : "prefix",
17342
+ buffer: "",
17343
+ prefixStripped: false
17344
+ };
17345
+ return;
17346
+ }
17347
+ if (chunk.type === "text-delta") {
17348
+ const block = textBlocks[chunk.id];
17349
+ if (!block) {
17350
+ controller.enqueue(chunk);
17351
+ return;
17352
+ }
17353
+ block.buffer += chunk.delta;
17354
+ if (block.phase === "buffering") return;
17355
+ if (block.phase === "prefix") {
17356
+ if (block.buffer.length > 0 && !block.buffer.startsWith("`")) {
17357
+ block.phase = "streaming";
17358
+ controller.enqueue(block.startEvent);
17359
+ } else if (block.buffer.startsWith("```")) {
17360
+ if (block.buffer.includes("\n")) {
17361
+ const prefixMatch = block.buffer.match(/^```(?:json)?\s*\n/);
17362
+ if (prefixMatch) {
17363
+ block.buffer = block.buffer.slice(prefixMatch[0].length);
17364
+ block.prefixStripped = true;
17365
+ block.phase = "streaming";
17366
+ controller.enqueue(block.startEvent);
17367
+ } else {
17368
+ block.phase = "streaming";
17369
+ controller.enqueue(block.startEvent);
17370
+ }
17371
+ }
17372
+ } else if (block.buffer.length >= 3 && !block.buffer.startsWith("```")) {
17373
+ block.phase = "streaming";
17374
+ controller.enqueue(block.startEvent);
17375
+ }
17376
+ }
17377
+ if (block.phase === "streaming" && block.buffer.length > SUFFIX_BUFFER_SIZE) {
17378
+ const toStream = block.buffer.slice(0, -12);
17379
+ block.buffer = block.buffer.slice(-12);
17380
+ controller.enqueue({
17381
+ type: "text-delta",
17382
+ id: chunk.id,
17383
+ delta: toStream
17384
+ });
17385
+ }
17386
+ return;
17387
+ }
17388
+ if (chunk.type === "text-end") {
17389
+ const block = textBlocks[chunk.id];
17390
+ if (block) {
17391
+ if (block.phase === "prefix" || block.phase === "buffering") controller.enqueue(block.startEvent);
17392
+ let remaining = block.buffer;
17393
+ if (block.phase === "buffering") remaining = transform(remaining);
17394
+ else if (block.prefixStripped) remaining = remaining.replace(/\n?```\s*$/, "").trimEnd();
17395
+ else remaining = transform(remaining);
17396
+ if (remaining.length > 0) controller.enqueue({
17397
+ type: "text-delta",
17398
+ id: chunk.id,
17399
+ delta: remaining
17400
+ });
17401
+ controller.enqueue(chunk);
17402
+ delete textBlocks[chunk.id];
17403
+ return;
17404
+ }
17405
+ }
17406
+ controller.enqueue(chunk);
17407
+ } })),
17408
+ ...rest
17409
+ };
17410
+ }
17411
+ };
17412
+ }
17413
+ var wrapLanguageModel = ({ model: inputModel, middleware: middlewareArg, modelId, providerId }) => {
17414
+ const model = asLanguageModelV4(inputModel);
17415
+ return [...asArray(middlewareArg)].reverse().reduce((wrappedModel, middleware) => {
17416
+ return doWrap({
17417
+ model: wrappedModel,
17418
+ middleware,
17419
+ modelId,
17420
+ providerId
17421
+ });
17422
+ }, model);
17423
+ };
17424
+ var doWrap = ({ model, middleware: { transformParams, wrapGenerate, wrapStream, overrideProvider, overrideModelId, overrideSupportedUrls }, modelId, providerId }) => {
17425
+ var _a22, _b, _c;
17426
+ async function doTransform({ params, type }) {
17427
+ return transformParams ? await transformParams({
17428
+ params,
17429
+ type,
17430
+ model
17431
+ }) : params;
17432
+ }
17433
+ return {
17434
+ specificationVersion: "v4",
17435
+ provider: (_a22 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a22 : model.provider,
17436
+ modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
17437
+ supportedUrls: (_c = overrideSupportedUrls == null ? void 0 : overrideSupportedUrls({ model })) != null ? _c : model.supportedUrls,
17438
+ async doGenerate(params) {
17439
+ const transformedParams = await doTransform({
17440
+ params,
17441
+ type: "generate"
17442
+ });
17443
+ const doGenerate = async () => await model.doGenerate(transformedParams);
17444
+ const doStream = async () => await model.doStream(transformedParams);
17445
+ return wrapGenerate ? await wrapGenerate({
17446
+ doGenerate,
17447
+ doStream,
17448
+ params: transformedParams,
17449
+ model
17450
+ }) : await doGenerate();
17451
+ },
17452
+ async doStream(params) {
17453
+ const transformedParams = await doTransform({
17454
+ params,
17455
+ type: "stream"
17456
+ });
17457
+ const doGenerate = async () => await model.doGenerate(transformedParams);
17458
+ const doStream = async () => await model.doStream(transformedParams);
17459
+ return wrapStream ? await wrapStream({
17460
+ doGenerate,
17461
+ doStream,
17462
+ params: transformedParams,
17463
+ model
17464
+ }) : await doStream();
17465
+ }
17466
+ };
17467
+ };
17297
17468
  createIdGenerator({
17298
17469
  prefix: "call",
17299
17470
  size: 24
@@ -46974,6 +47145,6 @@ function resolveWorkflowTool(workflow, context = {}) {
46974
47145
  });
46975
47146
  }
46976
47147
  //#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 };
47148
+ 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
47149
 
46979
- //# sourceMappingURL=dist-iDcp4e6O.mjs.map
47150
+ //# sourceMappingURL=dist-CB_SkwlE.mjs.map