@codelia/core 0.1.25 → 0.1.28

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/index.cjs CHANGED
@@ -2419,6 +2419,16 @@ var isOpenAIAssistantInputContent = (value) => {
2419
2419
  }
2420
2420
  return false;
2421
2421
  };
2422
+ var isReplayableOpenAIHistoryItem = (value) => {
2423
+ if (!value || typeof value !== "object") {
2424
+ return false;
2425
+ }
2426
+ const type = value.type;
2427
+ if (type === "reasoning") {
2428
+ return typeof value.id === "string";
2429
+ }
2430
+ return type === "web_search_call";
2431
+ };
2422
2432
  var isReplayableOpenAIFunctionCallItem = (value) => {
2423
2433
  if (!value || typeof value !== "object") {
2424
2434
  return false;
@@ -2592,6 +2602,9 @@ function toResponsesInput(messages) {
2592
2602
  continue;
2593
2603
  }
2594
2604
  if (message.role === "reasoning") {
2605
+ if (isReplayableOpenAIHistoryItem(message.raw_item)) {
2606
+ items.push(message.raw_item);
2607
+ }
2595
2608
  continue;
2596
2609
  }
2597
2610
  if (message.role === "assistant") {
@@ -3599,11 +3612,21 @@ var ChatOpenAI = class {
3599
3612
  instructionsHash: args.requestMeta.instructionsHash,
3600
3613
  toolsHash: args.requestMeta.toolsHash,
3601
3614
  model: args.requestMeta.model,
3602
- lastInput: args.request.input,
3615
+ lastInput: this.buildWsLastInput(args.request.input, args.response),
3603
3616
  ws: args.ws,
3604
3617
  lastUsedAt: Date.now()
3605
3618
  });
3606
3619
  }
3620
+ buildWsLastInput(requestInput, response) {
3621
+ if (!Array.isArray(requestInput)) {
3622
+ return requestInput;
3623
+ }
3624
+ const replayItems = toResponsesInput(toChatInvokeCompletion2(response).messages);
3625
+ if (replayItems.length === 0) {
3626
+ return requestInput;
3627
+ }
3628
+ return [...requestInput, ...replayItems];
3629
+ }
3607
3630
  async invokeViaWs(args) {
3608
3631
  return this.wsTransport.invoke(args);
3609
3632
  }
@@ -3671,7 +3694,7 @@ var ChatOpenAI = class {
3671
3694
  return void 0;
3672
3695
  }
3673
3696
  if (!Array.isArray(previousInput) || !Array.isArray(currentInput)) {
3674
- return safeJsonStringify(previousInput) === safeJsonStringify(currentInput) ? [] : null;
3697
+ return null;
3675
3698
  }
3676
3699
  if (previousInput.length > currentInput.length) {
3677
3700
  return null;
@@ -3682,7 +3705,7 @@ var ChatOpenAI = class {
3682
3705
  }
3683
3706
  }
3684
3707
  if (previousInput.length === currentInput.length) {
3685
- return [];
3708
+ return null;
3686
3709
  }
3687
3710
  return currentInput.slice(previousInput.length);
3688
3711
  }
@@ -4467,6 +4490,18 @@ var withRequiredProperties = (schema) => mapSchema(schema, (next) => {
4467
4490
  }
4468
4491
  return next;
4469
4492
  });
4493
+ var withTopLevelObjectTypeForObjectUnions = (schema) => {
4494
+ if (schema.type !== void 0) return schema;
4495
+ const variants = (Array.isArray(schema.anyOf) && schema.anyOf.length > 0 ? schema.anyOf : Array.isArray(schema.oneOf) && schema.oneOf.length > 0 ? schema.oneOf : null) ?? null;
4496
+ if (!variants) return schema;
4497
+ const allObjectVariants = variants.every((variant) => {
4498
+ if (!variant || typeof variant !== "object") return false;
4499
+ const jsonSchema = variant;
4500
+ return jsonSchema.type === "object";
4501
+ });
4502
+ if (!allObjectVariants) return schema;
4503
+ return { ...schema, type: "object" };
4504
+ };
4470
4505
  function toToolResult(value) {
4471
4506
  if (isToolResult(value)) return value;
4472
4507
  if (typeof value === "string") return { type: "text", text: value };
@@ -4479,8 +4514,8 @@ function defineTool(toolOptions) {
4479
4514
  target: "draft-07",
4480
4515
  io: "input"
4481
4516
  });
4482
- const strictParameters = withRequiredProperties(
4483
- withNoAdditionalProperties(parameters)
4517
+ const strictParameters = withTopLevelObjectTypeForObjectUnions(
4518
+ withRequiredProperties(withNoAdditionalProperties(parameters))
4484
4519
  );
4485
4520
  return {
4486
4521
  name: toolOptions.name,
package/dist/index.d.cts CHANGED
@@ -689,6 +689,7 @@ declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$1, OpenAI
689
689
  private invokeWithTransport;
690
690
  private invokeHttpTransportWithDebug;
691
691
  private persistWsSessionState;
692
+ private buildWsLastInput;
692
693
  private invokeViaWs;
693
694
  private closeWsSafely;
694
695
  private closeWsWithoutMaskingPrimaryError;
package/dist/index.d.ts CHANGED
@@ -689,6 +689,7 @@ declare class ChatOpenAI implements BaseChatModel<typeof PROVIDER_NAME$1, OpenAI
689
689
  private invokeWithTransport;
690
690
  private invokeHttpTransportWithDebug;
691
691
  private persistWsSessionState;
692
+ private buildWsLastInput;
692
693
  private invokeViaWs;
693
694
  private closeWsSafely;
694
695
  private closeWsWithoutMaskingPrimaryError;
package/dist/index.js CHANGED
@@ -2362,6 +2362,16 @@ var isOpenAIAssistantInputContent = (value) => {
2362
2362
  }
2363
2363
  return false;
2364
2364
  };
2365
+ var isReplayableOpenAIHistoryItem = (value) => {
2366
+ if (!value || typeof value !== "object") {
2367
+ return false;
2368
+ }
2369
+ const type = value.type;
2370
+ if (type === "reasoning") {
2371
+ return typeof value.id === "string";
2372
+ }
2373
+ return type === "web_search_call";
2374
+ };
2365
2375
  var isReplayableOpenAIFunctionCallItem = (value) => {
2366
2376
  if (!value || typeof value !== "object") {
2367
2377
  return false;
@@ -2535,6 +2545,9 @@ function toResponsesInput(messages) {
2535
2545
  continue;
2536
2546
  }
2537
2547
  if (message.role === "reasoning") {
2548
+ if (isReplayableOpenAIHistoryItem(message.raw_item)) {
2549
+ items.push(message.raw_item);
2550
+ }
2538
2551
  continue;
2539
2552
  }
2540
2553
  if (message.role === "assistant") {
@@ -3542,11 +3555,21 @@ var ChatOpenAI = class {
3542
3555
  instructionsHash: args.requestMeta.instructionsHash,
3543
3556
  toolsHash: args.requestMeta.toolsHash,
3544
3557
  model: args.requestMeta.model,
3545
- lastInput: args.request.input,
3558
+ lastInput: this.buildWsLastInput(args.request.input, args.response),
3546
3559
  ws: args.ws,
3547
3560
  lastUsedAt: Date.now()
3548
3561
  });
3549
3562
  }
3563
+ buildWsLastInput(requestInput, response) {
3564
+ if (!Array.isArray(requestInput)) {
3565
+ return requestInput;
3566
+ }
3567
+ const replayItems = toResponsesInput(toChatInvokeCompletion2(response).messages);
3568
+ if (replayItems.length === 0) {
3569
+ return requestInput;
3570
+ }
3571
+ return [...requestInput, ...replayItems];
3572
+ }
3550
3573
  async invokeViaWs(args) {
3551
3574
  return this.wsTransport.invoke(args);
3552
3575
  }
@@ -3614,7 +3637,7 @@ var ChatOpenAI = class {
3614
3637
  return void 0;
3615
3638
  }
3616
3639
  if (!Array.isArray(previousInput) || !Array.isArray(currentInput)) {
3617
- return safeJsonStringify(previousInput) === safeJsonStringify(currentInput) ? [] : null;
3640
+ return null;
3618
3641
  }
3619
3642
  if (previousInput.length > currentInput.length) {
3620
3643
  return null;
@@ -3625,7 +3648,7 @@ var ChatOpenAI = class {
3625
3648
  }
3626
3649
  }
3627
3650
  if (previousInput.length === currentInput.length) {
3628
- return [];
3651
+ return null;
3629
3652
  }
3630
3653
  return currentInput.slice(previousInput.length);
3631
3654
  }
@@ -4409,6 +4432,18 @@ var withRequiredProperties = (schema) => mapSchema(schema, (next) => {
4409
4432
  }
4410
4433
  return next;
4411
4434
  });
4435
+ var withTopLevelObjectTypeForObjectUnions = (schema) => {
4436
+ if (schema.type !== void 0) return schema;
4437
+ const variants = (Array.isArray(schema.anyOf) && schema.anyOf.length > 0 ? schema.anyOf : Array.isArray(schema.oneOf) && schema.oneOf.length > 0 ? schema.oneOf : null) ?? null;
4438
+ if (!variants) return schema;
4439
+ const allObjectVariants = variants.every((variant) => {
4440
+ if (!variant || typeof variant !== "object") return false;
4441
+ const jsonSchema = variant;
4442
+ return jsonSchema.type === "object";
4443
+ });
4444
+ if (!allObjectVariants) return schema;
4445
+ return { ...schema, type: "object" };
4446
+ };
4412
4447
  function toToolResult(value) {
4413
4448
  if (isToolResult(value)) return value;
4414
4449
  if (typeof value === "string") return { type: "text", text: value };
@@ -4421,8 +4456,8 @@ function defineTool(toolOptions) {
4421
4456
  target: "draft-07",
4422
4457
  io: "input"
4423
4458
  });
4424
- const strictParameters = withRequiredProperties(
4425
- withNoAdditionalProperties(parameters)
4459
+ const strictParameters = withTopLevelObjectTypeForObjectUnions(
4460
+ withRequiredProperties(withNoAdditionalProperties(parameters))
4426
4461
  );
4427
4462
  return {
4428
4463
  name: toolOptions.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codelia/core",
3
- "version": "0.1.25",
3
+ "version": "0.1.28",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -25,12 +25,12 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@anthropic-ai/sdk": "^0.78.0",
28
- "@codelia/config": "0.1.25",
29
- "@codelia/shared-types": "0.1.25",
28
+ "@codelia/config": "0.1.28",
29
+ "@codelia/shared-types": "0.1.28",
30
30
  "@google-cloud/vertexai": "^1.10.0",
31
31
  "@google/genai": "^1.37.0",
32
32
  "json-schema": "^0.4.0",
33
- "openai": "^6.24.0",
33
+ "openai": "^6.25.0",
34
34
  "zod": "^4.3.5"
35
35
  }
36
36
  }
package/prompts/system.md CHANGED
@@ -52,6 +52,9 @@ Assume:
52
52
  - Keep types tight in typed languages; avoid escaping the type system when safer narrowing is possible.
53
53
  - Prefer the smallest correct edit. Avoid broad refactors unless explicitly requested.
54
54
  - When editing, prefer `edit` for targeted patches; prefer `write` only when replacing an entire file is simpler/safer.
55
+ - Treat `edit` misses (for example `String not found in <path>`) as hard failures, not partial success.
56
+ - After an `edit`, verify the intended change (e.g. re-read target lines or inspect diff) before proceeding to follow-up edits.
57
+ - If an `edit` misses repeatedly on the same target, stop and re-locate the exact current text instead of retrying the same patch blindly.
55
58
 
56
59
  ## Workflow expectations
57
60
 
@@ -89,6 +92,10 @@ When implementing features/changes:
89
92
  - Create a short plan before execution for non-trivial tasks.
90
93
  - Keep the plan short, ordered, and update it when scope or facts change.
91
94
  - Skip formal plans for straightforward tasks; do not make single-step plans.
95
+ - For non-trivial work, maintain the plan with `todo_write` / `todo_read` instead of keeping it only in free-form text.
96
+ - Keep at most one todo item in `in_progress`; complete or reprioritize it before starting another.
97
+ - Use `todo_write` modes intentionally: `new` for initial/restart planning, `append` for newly discovered tasks, `patch` for progress/status updates by id, and `clear` when the plan should be reset.
98
+ - Before final response on non-trivial work, check `todo_read` and either finish pending work or explicitly report what remains.
92
99
 
93
100
  ## Special user requests
94
101