@mindstudio-ai/agent 0.1.99 → 0.1.101
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/README.md +113 -0
- package/dist/cli.js +387 -52
- package/dist/index.d.ts +520 -23
- package/dist/index.js +479 -42
- package/dist/index.js.map +1 -1
- package/dist/postinstall.js +387 -52
- package/llms.txt +12 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -374,6 +374,110 @@ mindstudio batch --no-meta '[...]'
|
|
|
374
374
|
|
|
375
375
|
Run `mindstudio batch` with no arguments for full usage help.
|
|
376
376
|
|
|
377
|
+
## Task agents
|
|
378
|
+
|
|
379
|
+
`runTask()` runs a multi-step tool-use loop: the model receives your prompt and a set of tools
|
|
380
|
+
(SDK actions and/or your own app's methods), calls them as needed, and produces structured
|
|
381
|
+
output. Use it when the task needs judgment between steps — research, enrichment, content
|
|
382
|
+
pipelines — rather than a fixed sequence of calls.
|
|
383
|
+
|
|
384
|
+
Define the output contract with `outputSchema` — plain JSON Schema in the same dialect as a
|
|
385
|
+
tool definition (`type`, `properties`, `required`, `enum`, `items`; nullability via type
|
|
386
|
+
arrays like `['string', 'null']`). The output is validated every turn with automatic repair,
|
|
387
|
+
and `result.output` is typed by inference from the schema — no generic argument, no manual
|
|
388
|
+
validation:
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
const result = await agent.runTask({
|
|
392
|
+
prompt: 'Find canonical info for this restaurant, then save it.',
|
|
393
|
+
input: { restaurantName: 'Tartine Bakery SF' },
|
|
394
|
+
tools: [
|
|
395
|
+
'searchGoogle',
|
|
396
|
+
'fetchUrl',
|
|
397
|
+
{ appMethod: 'saveRestaurant', description: 'Persist the researched restaurant.' },
|
|
398
|
+
],
|
|
399
|
+
outputSchema: {
|
|
400
|
+
type: 'object',
|
|
401
|
+
properties: {
|
|
402
|
+
name: { type: 'string' },
|
|
403
|
+
url: { type: ['string', 'null'] },
|
|
404
|
+
kind: { enum: ['bakery', 'cafe', 'restaurant'] },
|
|
405
|
+
},
|
|
406
|
+
required: ['name', 'kind'],
|
|
407
|
+
},
|
|
408
|
+
model: 'claude-5-sonnet', // any current tool-use model id
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
result.output.kind; // typed as 'bakery' | 'cafe' | 'restaurant'
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
With `outputSchema`, `runTask()` either returns conforming output or throws a
|
|
415
|
+
`MindStudioError` with `code === 'task_output_schema_mismatch'` (raw text and validation
|
|
416
|
+
errors in `err.details`) — it never resolves with garbage. Schemas outside the supported
|
|
417
|
+
dialect subset (`oneOf`, `$ref`, `nullable: true`, …) are rejected up front with
|
|
418
|
+
`task_output_schema_unsupported`. When building a schema in a variable rather than inline,
|
|
419
|
+
write it `as const satisfies JsonObjectSchema` to keep the literal inference.
|
|
420
|
+
|
|
421
|
+
The legacy alternative, `structuredOutputExample`, shapes output by example only: `output` is
|
|
422
|
+
typed by your generic argument and unvalidated — always check `result.parsedSuccessfully`
|
|
423
|
+
before using it.
|
|
424
|
+
|
|
425
|
+
App-method tools run as the user who invoked the method that started the task, with their
|
|
426
|
+
roles. Pass `onEvent` to stream progress (text chunks, tool calls, the final `done` event).
|
|
427
|
+
|
|
428
|
+
> `outputSchema` typing uses a `const` type parameter — consuming projects need
|
|
429
|
+
> TypeScript 5.0+.
|
|
430
|
+
|
|
431
|
+
## Jewels
|
|
432
|
+
|
|
433
|
+
A jewel is an agentic shadow companion for an app method — `foo.jewel.ts` beside `foo.ts`,
|
|
434
|
+
built with `defineJewel(method, { subject, propose, grade? })`. It proposes the method
|
|
435
|
+
input a careful operator would submit (or abstains with `input: null`), gets graded
|
|
436
|
+
against what a human actually did, and climbs an autonomy ladder (`shadow` → `approve` →
|
|
437
|
+
`auto`) declared in the app manifest.
|
|
438
|
+
|
|
439
|
+
For decision moments the app detects itself (an ingest branch that lands a row in a
|
|
440
|
+
pending state), hand the moment to the jewels from backend code:
|
|
441
|
+
|
|
442
|
+
```ts
|
|
443
|
+
mindstudio.waitUntil((async () => {
|
|
444
|
+
const merge = await mindstudio.jewels.propose(
|
|
445
|
+
'merge-issues', { sourceId: issue.id }, { idempotencyKey: issue.id });
|
|
446
|
+
if (merge.outcome !== 'committed') {
|
|
447
|
+
await mindstudio.jewels.propose(
|
|
448
|
+
'triage-issue', { issueId: issue.id }, { idempotencyKey: issue.id });
|
|
449
|
+
}
|
|
450
|
+
})());
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
The platform routes each proposal by the method's autonomy — `recorded` (shadow),
|
|
454
|
+
`queued` (approve), `committed` (auto: the method ran) — and `idempotencyKey` has Stripe
|
|
455
|
+
semantics (a replayed key returns the original outcome, so webhook retries are safe).
|
|
456
|
+
Backend/managed contexts only.
|
|
457
|
+
|
|
458
|
+
For `approve`-mode methods, build the review inbox natively in the app with
|
|
459
|
+
`jewels.queue`:
|
|
460
|
+
|
|
461
|
+
```ts
|
|
462
|
+
// Backend method — gate with the app's own reviewer role.
|
|
463
|
+
export async function listDraftReplies() {
|
|
464
|
+
auth.requireRole('support_lead');
|
|
465
|
+
return mindstudio.jewels.queue.list({ methodId: 'send-reply' });
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export async function reviewDraft({ itemId, action, edited }) {
|
|
469
|
+
auth.requireRole('support_lead');
|
|
470
|
+
return mindstudio.jewels.queue.resolve(itemId, {
|
|
471
|
+
action, // 'approve' | 'dismiss'
|
|
472
|
+
...(edited ? { input: edited } : {}), // an edit is captured with the pair
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
Approving **applies the target method as the signed-in reviewer** — the effect belongs
|
|
478
|
+
to the human who clicked, and the target method's own auth checks are the real gate on
|
|
479
|
+
who may approve. Unresolved items expire at the method's `attributionWindow`.
|
|
480
|
+
|
|
377
481
|
## Thread persistence
|
|
378
482
|
|
|
379
483
|
Steps execute within threads. Pass `$threadId` and `$appId` from a previous call to maintain state:
|
|
@@ -526,6 +630,15 @@ import type {
|
|
|
526
630
|
BatchStepResult,
|
|
527
631
|
ExecuteStepBatchOptions,
|
|
528
632
|
ExecuteStepBatchResult,
|
|
633
|
+
RunTaskOptions,
|
|
634
|
+
RunTaskResult,
|
|
635
|
+
JsonSchema,
|
|
636
|
+
JsonObjectSchema,
|
|
637
|
+
FromSchema,
|
|
638
|
+
JewelConfig,
|
|
639
|
+
JewelPairRecord,
|
|
640
|
+
JewelProposeOutcome,
|
|
641
|
+
JewelProposeResult,
|
|
529
642
|
} from '@mindstudio-ai/agent';
|
|
530
643
|
```
|
|
531
644
|
|