@nimiplatform/sdk 0.11.0 → 0.13.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 (98) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +77 -0
  3. package/dist/core/ai/index.d.ts +1 -0
  4. package/dist/core/ai/index.d.ts.map +1 -1
  5. package/dist/core/ai/index.js +1 -0
  6. package/dist/core/ai/index.js.map +1 -1
  7. package/dist/core/ai/local-app-model.d.ts +8 -0
  8. package/dist/core/ai/local-app-model.d.ts.map +1 -0
  9. package/dist/core/ai/local-app-model.js +144 -0
  10. package/dist/core/ai/local-app-model.js.map +1 -0
  11. package/dist/core/app/index.d.ts +7 -0
  12. package/dist/core/app/index.d.ts.map +1 -1
  13. package/dist/core/app/index.js +5 -0
  14. package/dist/core/app/index.js.map +1 -1
  15. package/dist/core/app/local-app-runtime-platform-ai.d.ts +28 -3
  16. package/dist/core/app/local-app-runtime-platform-ai.d.ts.map +1 -1
  17. package/dist/core/app/local-app-runtime-platform-ai.js +127 -74
  18. package/dist/core/app/local-app-runtime-platform-ai.js.map +1 -1
  19. package/dist/core/app/local-app-runtime-platform-direct-realtime-shared.d.ts +1 -1
  20. package/dist/core/app/local-app-runtime-platform-validation.d.ts +1 -1
  21. package/dist/core/app/local-app-runtime-platform-validation.d.ts.map +1 -1
  22. package/dist/core/app/local-app-runtime-platform-validation.js +4 -4
  23. package/dist/core/app/local-app-runtime-platform-validation.js.map +1 -1
  24. package/dist/core/app/local-app-runtime-platform-world-creator.d.ts +50 -0
  25. package/dist/core/app/local-app-runtime-platform-world-creator.d.ts.map +1 -0
  26. package/dist/core/app/local-app-runtime-platform-world-creator.js +246 -0
  27. package/dist/core/app/local-app-runtime-platform-world-creator.js.map +1 -0
  28. package/dist/core/app/local-app-runtime-platform.d.ts +4 -9
  29. package/dist/core/app/local-app-runtime-platform.d.ts.map +1 -1
  30. package/dist/core/app/local-app-runtime-platform.js +4 -2
  31. package/dist/core/app/local-app-runtime-platform.js.map +1 -1
  32. package/dist/core/app/local-app-text.d.ts +66 -0
  33. package/dist/core/app/local-app-text.d.ts.map +1 -0
  34. package/dist/core/app/local-app-text.js +274 -0
  35. package/dist/core/app/local-app-text.js.map +1 -0
  36. package/dist/core-generated/realm-client.js +6 -6
  37. package/dist/core-generated/realm-client.js.map +1 -1
  38. package/dist/core-generated/realm-typed-client.d.ts +12 -12
  39. package/dist/core-generated/realm-typed-client.d.ts.map +1 -1
  40. package/dist/core-generated/realm-typed-client.js +13 -13
  41. package/dist/core-generated/realm-typed-client.js.map +1 -1
  42. package/dist/core-generated/runtime-client.d.ts.map +1 -1
  43. package/dist/core-generated/runtime-client.js +40 -0
  44. package/dist/core-generated/runtime-client.js.map +1 -1
  45. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts +147 -3
  46. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts.map +1 -1
  47. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js +281 -7
  48. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js.map +1 -1
  49. package/dist/core-generated/runtime-protobuf/runtime/v1/app.d.ts +394 -0
  50. package/dist/core-generated/runtime-protobuf/runtime/v1/app.d.ts.map +1 -1
  51. package/dist/core-generated/runtime-protobuf/runtime/v1/app.js +877 -1
  52. package/dist/core-generated/runtime-protobuf/runtime/v1/app.js.map +1 -1
  53. package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts +4 -0
  54. package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts.map +1 -1
  55. package/dist/core-generated/runtime-protobuf/runtime/v1/common.js +4 -0
  56. package/dist/core-generated/runtime-protobuf/runtime/v1/common.js.map +1 -1
  57. package/dist/core-generated/runtime-public-client.d.ts.map +1 -1
  58. package/dist/core-generated/runtime-public-client.js +40 -0
  59. package/dist/core-generated/runtime-public-client.js.map +1 -1
  60. package/dist/core-generated/runtime-public-rpc-auth-posture.d.ts.map +1 -1
  61. package/dist/core-generated/runtime-public-rpc-auth-posture.js +5 -0
  62. package/dist/core-generated/runtime-public-rpc-auth-posture.js.map +1 -1
  63. package/dist/core-generated/runtime-public-wire-codecs.d.ts +6 -1
  64. package/dist/core-generated/runtime-public-wire-codecs.d.ts.map +1 -1
  65. package/dist/core-generated/runtime-public-wire-codecs.js +6 -1
  66. package/dist/core-generated/runtime-public-wire-codecs.js.map +1 -1
  67. package/dist/core-generated/runtime-rpc-auth-posture.d.ts.map +1 -1
  68. package/dist/core-generated/runtime-rpc-auth-posture.js +5 -0
  69. package/dist/core-generated/runtime-rpc-auth-posture.js.map +1 -1
  70. package/dist/core-generated/runtime-typed-client.d.ts +8 -3
  71. package/dist/core-generated/runtime-typed-client.d.ts.map +1 -1
  72. package/dist/core-generated/runtime-typed-client.js +50 -0
  73. package/dist/core-generated/runtime-typed-client.js.map +1 -1
  74. package/dist/core-generated/runtime-wire-codecs.d.ts +6 -1
  75. package/dist/core-generated/runtime-wire-codecs.d.ts.map +1 -1
  76. package/dist/core-generated/runtime-wire-codecs.js +6 -1
  77. package/dist/core-generated/runtime-wire-codecs.js.map +1 -1
  78. package/dist/realm/index.d.ts +1 -1
  79. package/dist/realm/index.d.ts.map +1 -1
  80. package/dist/realm/index.js +1 -1
  81. package/dist/realm/index.js.map +1 -1
  82. package/dist/runtime/desktop-first-party-runtime.d.ts +1 -1
  83. package/dist/runtime/desktop-first-party-runtime.d.ts.map +1 -1
  84. package/dist/runtime/desktop-first-party-runtime.js +5 -0
  85. package/dist/runtime/desktop-first-party-runtime.js.map +1 -1
  86. package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts +21 -1
  87. package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts.map +1 -1
  88. package/dist/runtime/first-party-protected-runtime-profiles.generated.js +6 -1
  89. package/dist/runtime/first-party-protected-runtime-profiles.generated.js.map +1 -1
  90. package/dist/runtime/wire-types/ai-scenario-types.d.ts +2 -2
  91. package/dist/runtime/wire-types/ai-scenario-types.d.ts.map +1 -1
  92. package/dist/runtime/wire-types/identity-app-types.d.ts +2 -2
  93. package/dist/runtime/wire-types/identity-app-types.d.ts.map +1 -1
  94. package/dist/runtime/wire-types/reason-code-enums.d.ts +1 -0
  95. package/dist/runtime/wire-types/reason-code-enums.d.ts.map +1 -1
  96. package/dist/runtime/wire-types/reason-code-enums.js +1 -0
  97. package/dist/runtime/wire-types/reason-code-enums.js.map +1 -1
  98. package/package.json +4 -2
@@ -1,4 +1,6 @@
1
- import { ExecutionMode, FaceSwapNoFacePolicy, FinishReason, ReasonCode as RuntimeReasonCode, RoutePolicy, ScenarioJobEventType, ScenarioJobStatus, ScenarioType, SpeechTimingMode, VideoContentRole, VideoContentType, VideoMode, VoiceAssetStatus, VoiceCreationSource, VoiceReferenceKind, VisionLocateGeometry, } from '../../core-generated/runtime-typed-client.js';
1
+ import { ChatContentPartType, ExecutionMode, FaceSwapNoFacePolicy, FinishReason, ResponseFormatKind, ToolChoiceMode, ReasonCode as RuntimeReasonCode, RoutePolicy, ScenarioJobEventType, ScenarioJobStatus, ScenarioType, SpeechTimingMode, VideoContentRole, VideoContentType, VideoMode, VoiceAssetStatus, VoiceCreationSource, VoiceReferenceKind, VisionLocateGeometry, } from '../../core-generated/runtime-typed-client.js';
2
+ import { toRuntimeMessages, toRuntimeTools, toRuntimeStruct, toNimiToolCall, toNimiTextOutputItems } from '../ai/runtime-model-text-projection.js';
3
+ import { validateLocalAppTextInput, projectLocalAppToolCall, projectLocalAppTextItems, projectLocalAppContinuity, modelTextOutputToLocalApp, localAppTextOutputToModel, } from './local-app-text.js';
2
4
  import { asRecord, assertExactKeys, assertExactProjectionKeys, assertNoAuthorityMaterial, assertSafeProjection, localAppError, localAppProjectionError, projectionText, requireText, } from './local-app-runtime-platform-validation.js';
3
5
  import { projectVisionLocateResult, localVisionLocateFromRuntime, runtimeVisionLocateFromLocal, localLocateGeometry, projectLocalExecutionInterruption, localInterruptionFromRuntime, runtimeInterruptionFromLocal, } from './local-app-runtime-platform-vision.js';
4
6
  const MAX_RESULT_BYTES = 256 * 1024;
@@ -11,15 +13,43 @@ export function createNimiLocalAppAIConsumptionClient(shell) {
11
13
  const client = {
12
14
  text: Object.freeze({
13
15
  streamTurn: async (input) => {
14
- let resultBytes = 0;
15
- return projectSubscription(await shell.text.streamTurn(validateTextTurnInput(input)), (value) => {
16
- const event = projectTextTurnEvent(value);
17
- if (event.type === 'delta') {
18
- resultBytes += utf8Length(event.text);
19
- if (resultBytes > MAX_RESULT_BYTES)
20
- localAppProjectionError('text-turn result size');
21
- }
22
- return event;
16
+ const stream = projectSubscription(await shell.text.streamTurn(validateLocalAppTextInput(input)), projectTextTurnEvent);
17
+ let canceled = false;
18
+ let closing;
19
+ const cancel = () => { canceled = true; return closing ??= stream.cancel(); };
20
+ return Object.freeze({
21
+ async *[Symbol.asyncIterator]() {
22
+ let sequence = 0n;
23
+ let terminal = false;
24
+ let hasPrimary = false;
25
+ const toolIds = new Set();
26
+ try {
27
+ for await (const event of stream) {
28
+ if (canceled)
29
+ break;
30
+ if (terminal || BigInt(event.sequence) !== ++sequence)
31
+ localAppProjectionError('text-turn event sequence');
32
+ if (event.type === 'delta')
33
+ hasPrimary = true;
34
+ if (event.type === 'tool-call') {
35
+ hasPrimary = true;
36
+ if (toolIds.has(event.toolCall.id))
37
+ localAppProjectionError('duplicate text tool call');
38
+ toolIds.add(event.toolCall.id);
39
+ }
40
+ if (event.type === 'completed' && !hasPrimary)
41
+ localAppProjectionError('missing primary text output');
42
+ terminal = event.type === 'completed' || event.type === 'failed';
43
+ yield event;
44
+ }
45
+ if (!terminal && !canceled)
46
+ localAppProjectionError('text-turn missing terminal event');
47
+ }
48
+ finally {
49
+ await cancel();
50
+ }
51
+ },
52
+ cancel,
23
53
  });
24
54
  },
25
55
  }),
@@ -236,63 +266,16 @@ export function createNimiLocalAppRuntimeScenarioJobClient(ai) {
236
266
  };
237
267
  return Object.freeze(client);
238
268
  }
239
- function validateTextTurnInput(input) {
240
- assertExactKeys(input, [
241
- 'messages', 'temperature', 'topP', 'maxTokens', 'topK',
242
- 'presencePenalty', 'frequencyPenalty', 'stop', 'seed',
243
- ], 'text-turn input');
244
- assertNoAuthorityMaterial(input);
245
- if (!Array.isArray(input.messages) || input.messages.length === 0 || input.messages.length > 8) {
246
- invalidAIInput('text-turn messages are invalid');
247
- }
248
- let totalBytes = 0;
249
- let sawSystem = false;
250
- let sawUser = false;
251
- const messages = input.messages.map((message, index) => {
252
- assertExactKeys(message, ['role', 'text'], `text-turn message ${index}`);
253
- if (message.role === 'system') {
254
- if (sawSystem || sawUser)
255
- invalidAIInput('text-turn system message order is invalid');
256
- sawSystem = true;
257
- }
258
- else if (message.role === 'user')
259
- sawUser = true;
260
- else
261
- invalidAIInput(`text-turn message ${index} role is invalid`);
262
- const text = boundedContent(message.text, `text-turn message ${index}`, 32 * 1024);
263
- totalBytes += utf8Length(message.role) + utf8Length(text);
264
- if (totalBytes > 64 * 1024)
265
- invalidAIInput('text-turn prompt is too large');
266
- return Object.freeze({ role: message.role, text });
267
- });
268
- if (!sawUser)
269
- invalidAIInput('text-turn requires a user message');
270
- optionalBoundedNumber(input.temperature, 'text-turn temperature', 0, 2);
271
- optionalBoundedNumber(input.topP, 'text-turn topP', 0, 1);
272
- optionalBoundedInteger(input.maxTokens, 'text-turn maxTokens', 0, 4096);
273
- optionalBoundedInteger(input.topK, 'text-turn topK', 0, Number.MAX_SAFE_INTEGER);
274
- optionalBoundedNumber(input.presencePenalty, 'text-turn presencePenalty', -2, 2);
275
- optionalBoundedNumber(input.frequencyPenalty, 'text-turn frequencyPenalty', -2, 2);
276
- optionalBoundedInteger(input.seed, 'text-turn seed', Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
277
- if (input.stop !== undefined && (!Array.isArray(input.stop)
278
- || input.stop.some((entry) => typeof entry !== 'string' || !entry.trim())))
279
- invalidAIInput('text-turn stop is invalid');
280
- return Object.freeze({
281
- messages: Object.freeze(messages),
282
- ...(input.temperature !== undefined ? { temperature: input.temperature } : {}),
283
- ...(input.topP !== undefined ? { topP: input.topP } : {}),
284
- ...(input.maxTokens !== undefined ? { maxTokens: input.maxTokens } : {}),
285
- ...(input.topK !== undefined ? { topK: input.topK } : {}),
286
- ...(input.presencePenalty !== undefined ? { presencePenalty: input.presencePenalty } : {}),
287
- ...(input.frequencyPenalty !== undefined ? { frequencyPenalty: input.frequencyPenalty } : {}),
288
- ...(input.stop !== undefined ? { stop: Object.freeze([...input.stop]) } : {}),
289
- ...(input.seed !== undefined ? { seed: input.seed } : {}),
290
- });
291
- }
292
269
  function validateScenarioSpec(spec, execute) {
293
270
  const record = asRecord(spec);
294
271
  if (!record || typeof record.type !== 'string')
295
272
  invalidAIInput('scenario spec is invalid');
273
+ if (record.type === 'text-generate') {
274
+ if (!execute)
275
+ invalidAIInput('text-generate is a single synchronous model step');
276
+ const { type: _type, ...input } = record;
277
+ return Object.freeze({ type: 'text-generate', ...validateLocalAppTextInput(input) });
278
+ }
296
279
  assertNoAuthorityMaterial(record);
297
280
  switch (record.type) {
298
281
  // @nimi-authority: rule.nimi.runtime.ai-provider.face-swap-video-job
@@ -562,31 +545,49 @@ function projectTextTurnEvent(value) {
562
545
  localAppProjectionError('text-turn event');
563
546
  const base = { sequence: String(record.sequence), traceId: boundedProjectionText(record.traceId, 'text-turn traceId', 512) };
564
547
  if (record.type === 'delta') {
565
- assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'text'], 'text-turn delta');
566
- return Object.freeze({ ...base, type: 'delta', text: boundedProjectionContent(record.text, 'text-turn text', 64 * 1024) });
548
+ assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'text', 'itemIndex'], 'text-turn delta');
549
+ return Object.freeze({ ...base, type: 'delta', text: boundedProjectionContent(record.text, 'text-turn text', 64 * 1024), itemIndex: projectionInteger(record.itemIndex, 'text item index', 0, 4_294_967_295) });
550
+ }
551
+ if (record.type === 'tool-call') {
552
+ assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'itemIndex', 'toolCall'], 'text tool call');
553
+ return Object.freeze({ ...base, type: 'tool-call', itemIndex: projectionInteger(record.itemIndex, 'tool item index', 0, 4_294_967_295), toolCall: projectLocalAppToolCall(record.toolCall) });
554
+ }
555
+ if (record.type === 'reasoning-continuity') {
556
+ assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'itemIndex', 'carrier'], 'text continuity');
557
+ return Object.freeze({ ...base, type: 'reasoning-continuity', itemIndex: projectionInteger(record.itemIndex, 'continuity item index', 0, 4_294_967_295), carrier: projectLocalAppContinuity(record.carrier) });
567
558
  }
568
559
  if (record.type === 'completed') {
569
560
  assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'finishReason'], 'text-turn completed');
570
- if (!['stop', 'length', 'content-filter'].includes(String(record.finishReason)))
561
+ if (!['stop', 'length', 'tool-calls', 'content-filter'].includes(String(record.finishReason)))
571
562
  localAppProjectionError('text-turn finishReason');
572
563
  return Object.freeze({ ...base, type: 'completed', finishReason: record.finishReason });
573
564
  }
574
565
  if (record.type === 'failed') {
575
- assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'reasonCode', 'actionHint'], 'text-turn failed');
576
- return Object.freeze({ ...base, type: 'failed', reasonCode: boundedProjectionText(record.reasonCode, 'text-turn reasonCode', 128), actionHint: optionalProjectionText(record.actionHint, 'text-turn actionHint', 512) });
566
+ assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'reasonCode', 'actionHint', ...(Object.hasOwn(record, 'interruption') ? ['interruption'] : [])], 'text-turn failed');
567
+ const interruption = projectLocalExecutionInterruption(record.interruption ?? undefined, record.reasonCode, 'failed');
568
+ return Object.freeze({ ...base, type: 'failed', reasonCode: boundedProjectionText(record.reasonCode, 'text-turn reasonCode', 128), actionHint: optionalProjectionText(record.actionHint, 'text-turn actionHint', 512), ...(interruption ? { interruption } : {}) });
577
569
  }
578
570
  return localAppProjectionError('text-turn event type');
579
571
  }
580
572
  function projectScenarioExecute(value) {
581
573
  const record = asRecord(value);
582
574
  assertExactProjectionKeys(record, ['output', 'traceId'], 'scenario execute');
583
- assertSafeProjection(record);
584
575
  const output = asRecord(record.output);
585
576
  if (!output)
586
577
  localAppProjectionError('scenario execute output');
587
578
  const traceId = boundedProjectionText(record.traceId, 'scenario execute traceId', 512);
579
+ if (output.type === 'text-generate') {
580
+ assertExactProjectionKeys(output, ['type', 'items', 'finishReason'], 'text generate output');
581
+ const items = projectLocalAppTextItems(output.items);
582
+ if (!['stop', 'length', 'tool-calls', 'content-filter'].includes(String(output.finishReason))
583
+ || (output.finishReason === 'tool-calls' && !items.some((item) => item.type === 'tool-call')))
584
+ localAppProjectionError('text finish reason');
585
+ return Object.freeze({ output: Object.freeze({ type: 'text-generate', items, finishReason: output.finishReason }), traceId });
586
+ }
587
+ assertSafeProjection(record);
588
588
  if (output.type === 'text-embed') {
589
- assertExactProjectionKeys(output, ['type', 'vectors'], 'text embed output');
589
+ assertExactProjectionKeys(output, ['type', 'vectors', 'spaceId'], 'text embed output');
590
+ const spaceId = boundedProjectionText(output.spaceId, 'embedding spaceId', 128);
590
591
  if (!Array.isArray(output.vectors) || output.vectors.length === 0 || output.vectors.length > 16)
591
592
  localAppProjectionError('text embed vectors');
592
593
  const vectors = output.vectors.map((vector) => {
@@ -595,7 +596,7 @@ function projectScenarioExecute(value) {
595
596
  localAppProjectionError('text embed vector');
596
597
  return Object.freeze([...vector]);
597
598
  });
598
- return Object.freeze({ output: Object.freeze({ type: 'text-embed', vectors: Object.freeze(vectors) }), traceId });
599
+ return Object.freeze({ output: Object.freeze({ type: 'text-embed', vectors: Object.freeze(vectors), spaceId }), traceId });
599
600
  }
600
601
  if (output.type === 'image-generate') {
601
602
  assertExactProjectionKeys(output, ['type', 'artifacts'], 'image execute output');
@@ -727,7 +728,7 @@ function projectArtifactUpload(value, expectedSize, expectedMimeType) {
727
728
  return Object.freeze({ artifactId, sizeBytes: record.sizeBytes, mimeType: record.mimeType });
728
729
  }
729
730
  function isArtifactUploadMime(value) {
730
- return value === 'image/png' || value === 'image/jpeg' || value === 'image/webp' || value === 'image/gif' || value === 'video/mp4';
731
+ return value === 'image/png' || value === 'image/jpeg' || value === 'image/webp' || value === 'image/gif' || value === 'audio/wav' || value === 'audio/mpeg' || value === 'video/mp4';
731
732
  }
732
733
  function projectArtifactRead(value) {
733
734
  const record = asRecord(value);
@@ -794,9 +795,42 @@ function projectRuntimeLocalAppVoiceAsset(asset) {
794
795
  expiresAt: plainRuntimeTimestamp(asset.expiresAt),
795
796
  };
796
797
  }
798
+ function runtimeLocalTextPart(part) {
799
+ if (part.type === 'text')
800
+ return { type: ChatContentPartType.TEXT, content: { oneofKind: 'text', text: part.text } };
801
+ if (part.type === 'image-url')
802
+ return { type: ChatContentPartType.IMAGE_URL, content: { oneofKind: 'imageUrl', imageUrl: { url: part.url, detail: '' } } };
803
+ return {
804
+ type: ChatContentPartType.ARTIFACT_REF,
805
+ content: { oneofKind: 'artifactRef', artifactRef: { artifactId: part.artifactId, localArtifactId: '', mimeType: part.mediaType, displayName: part.displayName ?? '' } },
806
+ };
807
+ }
797
808
  function runtimeTextTurnRequest(input) {
809
+ const messages = input.messages.map((message) => {
810
+ if (message.parts?.length)
811
+ return { role: message.role, text: '', turnItems: [], parts: message.parts.map(runtimeLocalTextPart) };
812
+ const [projected] = toRuntimeMessages([{
813
+ role: message.role,
814
+ content: message.turnItems?.length || message.role === 'assistant' ? [] : [{ type: 'text', text: message.text }],
815
+ turnItems: message.turnItems?.length ? message.turnItems.map((item) => item.type === 'output'
816
+ ? { ...item, output: localAppTextOutputToModel(item.output) } : item) : message.role === 'assistant'
817
+ ? [{ type: 'output', output: { type: 'text', text: message.text } }] : undefined,
818
+ }]);
819
+ return { role: message.role, text: projected.content, turnItems: projected.turnItems, parts: [] };
820
+ });
821
+ const choice = input.toolChoice;
822
+ const format = input.responseFormat;
798
823
  return {
799
- messages: input.messages.map((message) => ({ role: message.role, text: message.text })),
824
+ messages,
825
+ tools: toRuntimeTools(input.tools),
826
+ toolChoice: choice === 'none' ? ToolChoiceMode.NONE : choice === 'auto' ? ToolChoiceMode.AUTO
827
+ : choice === 'required' ? ToolChoiceMode.REQUIRED : choice ? ToolChoiceMode.TOOL : ToolChoiceMode.UNSPECIFIED,
828
+ toolChoiceName: typeof choice === 'object' ? choice.name : '',
829
+ responseFormat: format ? {
830
+ kind: format.type === 'json-schema' ? ResponseFormatKind.JSON_SCHEMA : format.type === 'json-object' ? ResponseFormatKind.JSON_OBJECT : ResponseFormatKind.TEXT,
831
+ jsonSchema: format.schema ? toRuntimeStruct(format.schema) : undefined,
832
+ schemaName: format.name ?? '', schemaDescription: format.description ?? '', strict: format.strict ?? false,
833
+ } : undefined,
800
834
  ...(input.temperature === undefined ? {} : { temperature: input.temperature }),
801
835
  ...(input.topP === undefined ? {} : { topP: input.topP }),
802
836
  ...(input.maxTokens === undefined ? {} : { maxTokens: input.maxTokens }),
@@ -808,6 +842,8 @@ function runtimeTextTurnRequest(input) {
808
842
  };
809
843
  }
810
844
  function runtimeExecuteRequest(spec) {
845
+ if (spec.type === 'text-generate')
846
+ return { spec: { oneofKind: 'textGenerate', textGenerate: runtimeTextTurnRequest(spec) } };
811
847
  if (spec.type === 'text-embed') {
812
848
  return { spec: { oneofKind: 'textEmbed', textEmbed: { inputs: [...spec.inputs] } } };
813
849
  }
@@ -995,8 +1031,19 @@ function runtimeVoiceReference(value) {
995
1031
  function projectRuntimeTextTurnEvent(event) {
996
1032
  const base = { sequence: event.sequence, traceId: event.traceId };
997
1033
  switch (event.payload.oneofKind) {
1034
+ case 'reasoningContinuity': {
1035
+ const carrier = event.payload.reasoningContinuity.carrier;
1036
+ if (!carrier)
1037
+ return localAppProjectionError('Runtime continuity carrier');
1038
+ return { ...base, type: 'reasoning-continuity', itemIndex: event.payload.reasoningContinuity.itemIndex,
1039
+ carrier: { ...carrier, payload: Array.from(carrier.payload) } };
1040
+ }
1041
+ case 'toolCall':
1042
+ if (!event.payload.toolCall.toolCall)
1043
+ return localAppProjectionError('Runtime tool call');
1044
+ return { ...base, type: 'tool-call', itemIndex: event.payload.toolCall.itemIndex, toolCall: toNimiToolCall(event.payload.toolCall.toolCall) };
998
1045
  case 'delta':
999
- return { ...base, type: 'delta', text: event.payload.delta.text };
1046
+ return { ...base, type: 'delta', text: event.payload.delta.text, itemIndex: event.payload.delta.itemIndex };
1000
1047
  case 'completed':
1001
1048
  return {
1002
1049
  ...base,
@@ -1009,6 +1056,7 @@ function projectRuntimeTextTurnEvent(event) {
1009
1056
  type: 'failed',
1010
1057
  reasonCode: runtimeReasonToken(event.payload.failed.reasonCode),
1011
1058
  actionHint: event.payload.failed.actionHint,
1059
+ ...(event.payload.failed.interruption ? { interruption: localInterruptionFromRuntime(event.payload.failed.interruption) } : {}),
1012
1060
  };
1013
1061
  default:
1014
1062
  return localAppProjectionError('text-turn Runtime event');
@@ -1016,11 +1064,14 @@ function projectRuntimeTextTurnEvent(event) {
1016
1064
  }
1017
1065
  function projectRuntimeScenarioExecuteResponse(response) {
1018
1066
  switch (response.output.oneofKind) {
1067
+ case 'textGenerate':
1068
+ return { output: { type: 'text-generate', items: toNimiTextOutputItems(response.output.textGenerate.items).map(modelTextOutputToLocalApp), finishReason: runtimeFinishReason(response.output.textGenerate.finishReason) }, traceId: response.traceId };
1019
1069
  case 'textEmbed':
1020
1070
  return {
1021
1071
  output: {
1022
1072
  type: 'text-embed',
1023
1073
  vectors: response.output.textEmbed.vectors.map((vector) => [...vector.values]),
1074
+ spaceId: response.output.textEmbed.spaceId,
1024
1075
  },
1025
1076
  traceId: response.traceId,
1026
1077
  };
@@ -1127,6 +1178,8 @@ function runtimeJobEventTypeName(value) {
1127
1178
  return types[value] ?? localAppProjectionError('scenario Runtime event type');
1128
1179
  }
1129
1180
  function runtimeFinishReason(value) {
1181
+ if (value === FinishReason.TOOL_CALL)
1182
+ return 'tool-calls';
1130
1183
  if (value === FinishReason.STOP)
1131
1184
  return 'stop';
1132
1185
  if (value === FinishReason.LENGTH)