@driftengine/ai 3.61.0

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.
Files changed (82) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +9 -0
  3. package/README.md +103 -0
  4. package/dist/adapters/local.d.ts +29 -0
  5. package/dist/adapters/local.js +24 -0
  6. package/dist/adapters/proxy.d.ts +28 -0
  7. package/dist/adapters/proxy.js +138 -0
  8. package/dist/bridges/authority.d.ts +153 -0
  9. package/dist/bridges/authority.js +179 -0
  10. package/dist/bridges/navigation.d.ts +100 -0
  11. package/dist/bridges/navigation.js +139 -0
  12. package/dist/budget/budget.d.ts +34 -0
  13. package/dist/budget/budget.js +57 -0
  14. package/dist/command/apply.d.ts +24 -0
  15. package/dist/command/apply.js +40 -0
  16. package/dist/command/log.d.ts +55 -0
  17. package/dist/command/log.js +50 -0
  18. package/dist/context/assemble.d.ts +48 -0
  19. package/dist/context/assemble.js +55 -0
  20. package/dist/context/continuation.d.ts +14 -0
  21. package/dist/context/continuation.js +36 -0
  22. package/dist/describe/manifest.d.ts +70 -0
  23. package/dist/describe/manifest.js +99 -0
  24. package/dist/entities/context.d.ts +52 -0
  25. package/dist/entities/context.js +83 -0
  26. package/dist/index.d.ts +61 -0
  27. package/dist/index.js +40 -0
  28. package/dist/policy/types.d.ts +55 -0
  29. package/dist/policy/types.js +26 -0
  30. package/dist/policy/utility.d.ts +18 -0
  31. package/dist/policy/utility.js +47 -0
  32. package/dist/provider/create.d.ts +16 -0
  33. package/dist/provider/create.js +57 -0
  34. package/dist/provider/latency.d.ts +27 -0
  35. package/dist/provider/latency.js +52 -0
  36. package/dist/provider/types.d.ts +90 -0
  37. package/dist/provider/types.js +8 -0
  38. package/dist/realtime/session.d.ts +35 -0
  39. package/dist/realtime/session.js +34 -0
  40. package/dist/session/agent.d.ts +217 -0
  41. package/dist/session/agent.js +506 -0
  42. package/dist/session/replay.d.ts +32 -0
  43. package/dist/session/replay.js +81 -0
  44. package/dist/session/states.d.ts +28 -0
  45. package/dist/session/states.js +33 -0
  46. package/dist/session/usage.d.ts +43 -0
  47. package/dist/session/usage.js +38 -0
  48. package/dist/testing/deterministic.d.ts +65 -0
  49. package/dist/testing/deterministic.js +150 -0
  50. package/dist/tools/policy.d.ts +47 -0
  51. package/dist/tools/policy.js +84 -0
  52. package/dist/tools/registry.d.ts +69 -0
  53. package/dist/tools/registry.js +75 -0
  54. package/dist/tools/validate.d.ts +24 -0
  55. package/dist/tools/validate.js +80 -0
  56. package/package.json +59 -0
  57. package/src/adapters/local.ts +64 -0
  58. package/src/adapters/proxy.ts +187 -0
  59. package/src/bridges/authority.ts +244 -0
  60. package/src/bridges/navigation.ts +207 -0
  61. package/src/budget/budget.ts +73 -0
  62. package/src/command/apply.ts +52 -0
  63. package/src/command/log.ts +81 -0
  64. package/src/context/assemble.ts +104 -0
  65. package/src/context/continuation.ts +39 -0
  66. package/src/describe/manifest.ts +148 -0
  67. package/src/entities/context.ts +112 -0
  68. package/src/index.ts +94 -0
  69. package/src/policy/types.ts +70 -0
  70. package/src/policy/utility.ts +53 -0
  71. package/src/provider/create.ts +70 -0
  72. package/src/provider/latency.ts +57 -0
  73. package/src/provider/types.ts +96 -0
  74. package/src/realtime/session.ts +63 -0
  75. package/src/session/agent.ts +622 -0
  76. package/src/session/replay.ts +96 -0
  77. package/src/session/states.ts +63 -0
  78. package/src/session/usage.ts +66 -0
  79. package/src/testing/deterministic.ts +204 -0
  80. package/src/tools/policy.ts +114 -0
  81. package/src/tools/registry.ts +122 -0
  82. package/src/tools/validate.ts +92 -0
@@ -0,0 +1,92 @@
1
+ import type { ToolSchema } from './registry.ts';
2
+
3
+ export type ValidationResult =
4
+ | { readonly ok: true; readonly value: unknown }
5
+ | { readonly ok: false; readonly reason: string; readonly path: string };
6
+
7
+ /**
8
+ * Check a model's arguments against a tool's schema.
9
+ *
10
+ * **Never throws.** A model producing bad arguments is ordinary rather than
11
+ * exceptional — it is the thing schemas exist for — and putting the ordinary case on
12
+ * the exception path means every call site needs a `try` it will eventually forget.
13
+ *
14
+ * **An unknown field is a failure, not something to drop.** A model inventing a field
15
+ * is a signal: it means the prompt and the schema disagree about the tool's shape, and
16
+ * silently discarding it is how that disagreement survives a release. *What it costs:*
17
+ * a provider that helpfully adds metadata to a tool call breaks until the schema names
18
+ * it. *What would make it wrong:* if a mainstream provider does that unavoidably, the
19
+ * answer is a declared passthrough field rather than a blanket tolerance.
20
+ */
21
+ export function validateArgs(schema: ToolSchema, args: unknown): ValidationResult {
22
+ const failure = check(schema, args, '');
23
+ return failure ?? { ok: true, value: args };
24
+ }
25
+
26
+ function fail(path: string, reason: string): ValidationResult {
27
+ return { ok: false, reason, path };
28
+ }
29
+
30
+ function check(schema: ToolSchema, value: unknown, path: string): ValidationResult | null {
31
+ switch (schema.kind) {
32
+ case 'string':
33
+ case 'number':
34
+ case 'boolean': {
35
+ const actual = typeof value;
36
+ if (actual !== schema.kind) {
37
+ return fail(path, `expected ${schema.kind}, received ${describe(value)}`);
38
+ }
39
+ return null;
40
+ }
41
+
42
+ case 'enum': {
43
+ if (typeof value !== 'string' || !schema.values.includes(value)) {
44
+ return fail(
45
+ path,
46
+ `expected one of ${schema.values.join(', ')}, received ${describe(value)}`,
47
+ );
48
+ }
49
+ return null;
50
+ }
51
+
52
+ case 'array': {
53
+ if (!Array.isArray(value)) return fail(path, `expected array, received ${describe(value)}`);
54
+ for (let i = 0; i < value.length; i++) {
55
+ const failure = check(schema.of, value[i], `${path}[${i}]`);
56
+ if (failure !== null) return failure;
57
+ }
58
+ return null;
59
+ }
60
+
61
+ case 'object': {
62
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
63
+ return fail(path, `expected object, received ${describe(value)}`);
64
+ }
65
+
66
+ const record = value as Record<string, unknown>;
67
+ for (const [name, field] of Object.entries(schema.fields)) {
68
+ const at = path === '' ? name : `${path}.${name}`;
69
+ if (!(name in record)) return fail(at, `missing required field`);
70
+ const failure = check(field, record[name], at);
71
+ if (failure !== null) return failure;
72
+ }
73
+
74
+ for (const name of Object.keys(record)) {
75
+ if (name in schema.fields) continue;
76
+ const at = path === '' ? name : `${path}.${name}`;
77
+ return fail(at, `unknown field, not in the schema`);
78
+ }
79
+
80
+ return null;
81
+ }
82
+
83
+ default:
84
+ return fail(path, `unrecognised schema kind`);
85
+ }
86
+ }
87
+
88
+ function describe(value: unknown): string {
89
+ if (value === null) return 'null';
90
+ if (Array.isArray(value)) return 'array';
91
+ return typeof value;
92
+ }